使用Chrome自定义标签登录SSO

时间:2020-02-25 09:54:21

标签: android single-sign-on deep-linking chrome-custom-tabs

在我的应用中,我需要通过网页登录。成功登录后,它将以“ my-app:/ auth?code = xxxxxx&status = xxxxx”的形式返回响应的标头。我在APP中配置了自定义架构。

打开Chrome自定义标签的代码:

StringBuilder url = new StringBuilder(<url>);
        url=url.append("&response_type=code");
        url=url.append("&redirect_uri=");
        url=url.append("my-app:/auth");
        CustomTabsSession session = getSession();
        CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
        intentBuilder.setToolbarColor(Color.parseColor("#ffffff"));
        intentBuilder.setShowTitle(true);
        intentBuilder.setNavigationBarColor(Color.parseColor("#ffffff"));
        intentBuilder.setSecondaryToolbarColor(Color.parseColor("#ffffff"));
        intentBuilder.setSession(session);
        CustomTabsIntent customTabsIntent=intentBuilder.build();
        CustomTabsHelper.addKeepAliveExtra(this, customTabsIntent.intent);
        CustomTabActivityHelper.openCustomTab(this, customTabsIntent, Uri.parse(url.toString()),
                (activity, uri1) -> {
                    showProgressDialog();
                    Bundle bundle = new Bundle();
                    bundle.putInt("screen_type", type);
                    LoginWebViewFragment loginWebViewFragment = LoginWebViewFragment.getInstance();
                    loginWebViewFragment.setArguments(bundle);
                    startNewFragment(loginWebViewFragment, "LoginWebViewFragment");
                });

在清单文件中配置的架构:

<activity
            android:name="<myActivity>"
            android:screenOrientation="portrait"
            android:theme="@style/transparent_status_bar" >
            <intent-filter>
                <data android:scheme="my-app" />
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
            </intent-filter>
        </activity>

成功登录后,该应用程序无法打开。是否可以从Chrome自定义标签重定向到应用?

1 个答案:

答案 0 :(得分:2)

您在重定向URI中缺少斜线:my-app:/auth应该为my-app://auth