this is my manifest file:
<activity
android:name=".activities.LoginActivity">
<intent-filter>
<action android:name="com.dyafat.HANDLE_AUTHORIZATION_RESPONSE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="net.openid.appauth.RedirectUriReceiverActivity"
tools:node="replace">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="com.dyafat"/>
</intent-filter>
</activity>
this is my activity file: onclick of button i am calling this method
private static final String AUTHORIZATION_ACTION="com.dyafat.HANDLE_AUTHORIZATION_RESPONSE";
Uri authorizationEndpoint = Uri.parse("https://--my auth uri-----/authorize");
Uri tokenEndpoint =Uri.parse("https://---- my toekn uri ---------/token");
String clientId = "client_id";
String responseType = AuthorizationRequest.RESPONSE_TYPE_CODE;
Uri redirectUri = Uri.parse("my_uri/oauth2callback");
public void performAuthorizationRequest() {
AuthorizationService service = new AuthorizationService(this);
AuthorizationRequest.Builder builder = new AuthorizationRequest.Builder(
new AuthorizationServiceConfiguration(
authorizationEndpoint,
tokenEndpoint), clientId, responseType, redirectUri);
AuthorizationRequest request = builder
.setScope("openid profile email")
.build();
service.performAuthorizationRequest(request,
PendingIntent.getActivity(this,
request.hashCode(),
new Intent(AUTHORIZATION_ACTION),
0));
service.dispose();
}
@Override
protected void onStart()
{
super.onStart();
checkIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
checkIntent(intent);
}
private void checkIntent( Intent intent)
{ if (intent != null)
{
if (Constants.Login.equals("1"))
{
intent.setAction(AUTHORIZATION_ACTION);
}
String action = intent.getAction();
if (action!=null)
{
switch (action)
{
case AUTHORIZATION_ACTION:
if (!intent.hasExtra(USED_INTENT))
{
handleAuthorizationResponse(intent);
intent.putExtra(USED_INTENT, true);
}
break;
default:
// do nothing
}
}
}
}
private void handleAuthorizationResponse(@NonNull Intent intent) {
AuthorizationResponse response = AuthorizationResponse.fromIntent(intent);
AuthorizationException error = AuthorizationException.fromIntent(intent);
if (response != null)
{
final AuthState authState = new AuthState(response, error);
Log.e("LOG_TAG", String.format("Handled Authorization Response %s ", authState.toString()));
AuthorizationService service = new AuthorizationService(this);
service.performTokenRequest(response.createTokenExchangeRequest(), new AuthorizationService.TokenResponseCallback() {
@Override
public void onTokenRequestCompleted(@Nullable TokenResponse tokenResponse, @Nullable AuthorizationException exception) {
if (exception != null) {
Log.e("LOG_TAG", "Token Exchange failed "+ exception);
} else {
if (tokenResponse != null)
{
accessToken=tokenResponse.accessToken;
Log.e("LOG_TAG", String.format("Token Response [ Access Token: %s, ID Token: %s ]", tokenResponse.accessToken, tokenResponse.idToken));
authState.update(tokenResponse, exception);
// persistAuthState(authState);
// Log.i(LOG_TAG, String.format("Token Response [ Access Token: %s, ID Token: %s ]", tokenResponse.accessToken, tokenResponse.idToken));
}
}
}
});
}
}
Error what i am getting:
2020-08-11 21:10:48.255 15269-15269/com.google.codelabs.appauth W/AppAuthSample: Token Exchange failed AuthorizationException: {"type":0,"code":3,"errorDescription":"Network error"} at net.openid.appauth.AuthorizationService$TokenRequestTask.doInBackground(AuthorizationService.java:244) at net.openid.appauth.AuthorizationService$TokenRequestTask.doInBackground(AuthorizationService.java:206) at android.os.AsyncTask$2.call(AsyncTask.java:333) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent .ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) Caused by: java.io.FileNotFoundException: https://----- MY -TOKEN URL ------/connect/token at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251) at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(Unknown Source:0) at net.openid.appauth.AuthorizationService$TokenR equestTask.doInBackground(AuthorizationService.java:239)
I would try to use an absolute URL here:
Uri redirectUri = Uri.parse("my_uri/oauth2callback");
See this question
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.