Created
July 25, 2019 09:41
-
-
Save GitEliteNovice/f2dd1f435aad32ae73088d84f7220ad3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String authorizationUrl) { | |
//This method will be called when the Auth proccess redirect to our RedirectUri. | |
//We will check the url looking for our RedirectUri. | |
if (authorizationUrl.startsWith(REDIRECT_URI)) { | |
Log.i("Authorize", ""); | |
Uri uri = Uri.parse(authorizationUrl); | |
//We take from the url the authorizationToken and the state token. We have to check that the state token returned by the Service is the same we sent. | |
//If not, that means the request may be a result of CSRF and must be rejected. | |
String stateToken = uri.getQueryParameter(STATE_PARAM); | |
if (stateToken == null || !stateToken.equals(STATE)) { | |
Log.e("Authorize", "State token doesn't match"); | |
return true; | |
} | |
//If the user doesn't allow authorization to our application, the authorizationToken Will be null. | |
String authorizationToken = uri.getQueryParameter(RESPONSE_TYPE_VALUE); | |
if (authorizationToken == null) { | |
Log.i("Authorize", "The user doesn't allow authorization."); | |
return true; | |
} | |
Log.i("Authorize", "Auth token received: " + authorizationToken); | |
//Generate URL for requesting Access Token | |
String accessTokenUrl = getAccessTokenUrl(authorizationToken); | |
//We make the request in a AsyncTask | |
new PostRequestAsyncTask().execute(accessTokenUrl); | |
} else { | |
//Default behaviour | |
Log.i("Authorize", "Redirecting to: " + authorizationUrl); | |
webView.loadUrl(authorizationUrl); | |
} | |
return true; | |
} | |
}); | |
String authUrl = getAuthorizationUrl(); | |
Log.i("Authorize", "Loading Auth Url: " + authUrl); | |
webView.loadUrl(authUrl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you help me add this to my project