如何解决openid应用程序身份验证自定义社交登录,给出异常ANDROID
这是我的清单文件:
<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>
私有静态最终字符串AUTHORIZATION_ACTION =“ com.dyafat.HANDLE_AUTHORIZATION_RESPONSE”;
Uri授权端点= 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,tokenResponse.idToken));
}
}
}
});
}
}
我得到的错误:
2020-08-11 21:10:48.255 15269-15269 / com.google.codelabs.appauth W / AppAuthSample:令牌交换失败 AuthorizationException:{“类型”:0,“代码”:3,“ errorDescription”:“网络错误”} 在net.openid.appauth.AuthorizationService $ TokenRequestTask.doInBackground(AuthorizationService.java:244) 在net.openid.appauth.AuthorizationService $ TokenRequestTask.doInBackground(AuthorizationService.java:206) 在android.os.AsyncTask $ 2.call(AsyncTask.java:333) 在java.util.concurrent.FutureTask.run(FutureTask.java:266) 在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:245) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:636) 在java.lang.Thread.run(Thread.java:764) 造成原因:java.io.FileNotFoundException:https:// ----- MY -TOKEN URL ------ / connect / token 在com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251) 在com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210) 在com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(未知源:0) 在net.openid.appauth.AuthorizationService $ TokenRequestTask.doInBackground(AuthorizationService.java:239)
解决方法
我会在这里尝试使用绝对URL:
Uri redirectUri = Uri.parse("my_uri/oauth2callback");
看到这个问题
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。