2

我正在尝试为我的 android 应用程序配置SSO 身份验证。我在下面的链接上找到了一个教程,

https://codelabs.developers.google.com/codelabs/appauth-android-codelab/#0

它显示了基于 Google 的SSO示例。

我为此目的使用Okta ,我在Okta上创建了应用程序并复制了客户端 ID 并将 url 从它重定向到我的项目。

当我使用谷歌 URL(身份验证和令牌端点、客户端 ID、重定向 URL)时,它工作正常,即它重定向到谷歌登录页面,输入有效凭据后,它返回到我的应用程序。

在使用Okta URL(身份验证和令牌端点、客户端 ID、重定向 URL)时,它会将我正确重定向到 Okta 登录页面,但在输入有效凭据后,它不会返回到我的应用程序,即登录页面没有关闭。

下面是我用于SSO登录的代码,

AuthorizationServiceConfiguration serviceConfiguration = new AuthorizationServiceConfiguration(
    //Uri.parse("https://accounts.google.com/o/oauth2/v2/auth") /* google auth endpoint */,
    //Uri.parse("https://www.googleapis.com/oauth2/v4/token") /* google token endpoint */
    Uri.parse("https://dev-636680.okta.com/oauth2/default/v1/authorize") /* okta auth endpoint */,
    Uri.parse("https://dev-636680.okta.com/oauth2/default/v1/token") /* okta token endpoint */
);

//String clientId = "511828570984-fuprh0cm7665emlne3rnf9pk34kkn86s.apps.googleusercontent.com";  // google 
String clientId = "0oahkjjk3oszDWqvZ356";                                // Okta
//Uri redirectUri = Uri.parse("com.google.codelabs.appauth:/oauth2callback");      // google
Uri redirectUri = Uri.parse("com.okta.dev-636680:/callback");            //okta
AuthorizationRequest.Builder builder = new AuthorizationRequest.Builder(
    serviceConfiguration,
    clientId,
    AuthorizationRequest.RESPONSE_TYPE_CODE,
    redirectUri
);
builder.setScopes("openid", "profile", "offline_access", "email");

AuthorizationRequest request = builder.build();

AuthorizationService authorizationService = new 
    AuthorizationService(view.getContext());

String action = "com.google.codelabs.appauth.HANDLE_AUTHORIZATION_RESPONSE";
Intent postAuthorizationIntent = new Intent(action);
PendingIntent pendingIntent = PendingIntent.getActivity(view.getContext(), request.hashCode(), postAuthorizationIntent, 0);
authorizationService.performAuthorizationRequest(request, pendingIntent);

请帮帮我。提前致谢。

4

0 回答 0