Open HolimaX opened 4 years ago
The redirect URI you pass to withRedirect
should be the URL that the server redirected to after the user has granted access. I probably should point that out in the example.
When you finish the interactive Authorization Code Grant in the browser window the OAuth2 auth endpoint redirects to your redirectUri
(the one you passed to BasicOAuth2Client
) but it appends a URI query parameter which contains the auth code. If that auth code is not present you'll get the said exception in BasicOAuth2AuthCodeAuthorization, line 45.
Your code only passes the base redirect URL, without the query parameters, hence the exception.
For example, if your redirect URL is http://localhost
, the server would redirect the browser to http://localhost?code=xyz
.
Please make sure you catch and pass the redirect URL you get from the server. Also see the diagram in https://tools.ietf.org/html/rfc6749#section-4.1, what we need is the result of step (C).
The redirect URI you pass to
withRedirect
should be the URL that the server redirected to after the user has granted access. I probably should point that out in the example.When you finish the interactive Authorization Code Grant in the browser window the OAuth2 auth endpoint redirects to your
redirectUri
(the one you passed toBasicOAuth2Client
) but it appends a URI query parameter which contains the auth code. If that auth code is not present you'll get the said exception in BasicOAuth2AuthCodeAuthorization, line 45. Your code only passes the base redirect URL, without the query parameters, hence the exception.For example, if your redirect URL is
http://localhost
, the server would redirect the browser tohttp://localhost?code=xyz
.Please make sure you catch and pass the redirect URL you get from the server. Also see the diagram in https://tools.ietf.org/html/rfc6749#section-4.1, what we need is the result of step (C).
Ok, yeah, I already spent two days trying to get webview working and I did it. Anyhow - some simple example would help to speed up things for other users! :) You can add link to README that this step is needed as per OAUTH2 design....
P.S. Kudos for this library anyways! :)
@HolimaX - Do you have an example with WebView?
@dmfs @HolimaX Just a question regarding this flow... I was following this page https://developer.webex.com/blog/real-world-walkthrough-of-building-an-oauth-webex-integration in order to use oauth2 against webex api - I already took the "grant" part out and I've got the "response code": can I take that response code and write my java code to grab the token directly? Or, must I run always the grant part at every token request?
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:
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);