Skip to content

NPE error when using sample code #77

@HolimaX

Description

@HolimaX

There seems to be issue with sample, provided in Readme. The code cannot resolve the 'redirectUri' variable. I tried to workaround by using 'client.', but it fails. See below for details.

When using:

                        HttpRequestExecutor executor = new HttpUrlConnectionExecutor();

                        // Create OAuth2 provider
                        OAuth2AuthorizationProvider provider = new BasicOAuth2AuthorizationProvider(
                                URI.create("https://.../oauth/authorize"),
                                URI.create("https://.../oauth/token"),
                                new Duration(1, 0, 3600) /* default expiration time in case the server doesn't return any */);

                        // Create OAuth2 client credentials
                        OAuth2ClientCredentials credentials = new BasicOAuth2ClientCredentials(
                                list.get(2).toString(), "...");

                        // Create OAuth2 client
                        OAuth2Client client = new BasicOAuth2Client(
                                provider,
                                credentials,
                                new LazyUri(new Precoded(redirectUrl)) /* Redirect URL */);

                        // Start an interactive Authorization Code Grant
                        OAuth2InteractiveGrant grant = new AuthorizationCodeGrant(
                                client, new BasicScope("blablabla"));

                        // Get the authorization URL and open it in a WebView
                        URI authorizationUrl = grant.authorizationUrl();

                        // Open the URL in a WebView and wait for the redirect to the redirect URL
                        // After the redirect, feed the URL to the grant to retrieve the access token
                        OAuth2AccessToken token = grant.withRedirect(client.redirectUri()).accessToken(executor);

I am receiving:
java.util.NoSuchElementException: No value is present in this Optional. Better call isPresent() next time.

In methoid call:
OAuth2AccessToken token = grant.withRedirect(client.redirectUri()).accessToken(executor);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions