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>

这是我的活动文件:按钮的onclick我正在调用此方法

私有静态最终字符串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");

看到这个问题

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...