使用 MSAL 在原生 Android 中加载用户流的 Azure Adb2c 自定义 Web 视图

问题描述

我使用 MSAL 将 azure adb2c 集成到我的原生 android 应用程序中。目前我正在为我的应用程序使用 createSingleAccountPublicclientApplication。我已经创建了 sign-up and sign-in user flow 并与我的应用程序完美集成。当应用程序启动时,它重定向到 Web 视图,因为我在清单文件中提到了 browsertabactivity。但是根据我们的要求,我们必须创建自己的 custom webview显示所有 userflows 并根据需要获取回调。是否可以为 android 创建 custom webview显示用户流程?

第二个问题是,当用户注册页面点击 back button 时,会抛出错误代码 AADB2C90091,而不是返回 signIn UserFlow Page 。如何在按下后显示 signIn UserFlow 页面

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.microsoft_azure);
        context = MicrosoftAzureActivity.this;
        initializeUI();

        // Creates a PublicclientApplication object with res/raw/auth_config_single_account.json
        PublicclientApplication.createSingleAccountPublicclientApplication(MicrosoftAzureActivity.this,R.raw.auth_config_single_account,new IPublicclientApplication.ISingleAccountApplicationCreatedListener() {
                    @Override
                    public void onCreated(ISingleAccountPublicclientApplication application) {
                        /**
                         * This test app assumes that the app is only going to support one account.
                         * This requires "account_mode" : "SINGLE" in the config json file.
                         **/
                        mSingleAccountApp = application;

                        loadAccount();
                    }

                    @Override
                    public void onError(MsalException exception) {
                        displayError(exception);
                    }
                });

    }

loadAccount::

 private void loadAccount() {
        if (mSingleAccountApp == null) {

            return;
        }
         mSingleAccountApp.getCurrentAccountAsync(new ISingleAccountPublicclientApplication.CurrentAccountCallback() {
            @Override
            public void onAccountLoaded(@Nullable IAccount activeAccount) {
                // You can use the account data to update your UI or your app database.
                mAccount = activeAccount;
                if (activeAccount != null) {
              mSingleAccountApp.acquiretokenSilentAsync(getScopes(),B2CConfiguration.getAuthorityFromPolicyName("B2C_1_SignInSignUp"),getAuthSilentCallback());

                }
            }

            @Override
            public void onAccountChanged(@Nullable IAccount priorAccount,@Nullable IAccount currentAccount) {
                if (currentAccount == null) {
                    // Perform a cleanup task as the signed-in account changed.
                    showToastOnSignOut();
                }
            }

            @Override
            public void onError(@NonNull MsalException exception) {
                displayError(exception);
            }
        });
    }

auth_config_single_account::

{
  "client_id" : "cfsttrtkg-4545-fsrdh-822d-53453423-0","redirect_uri" : "msauth://**********/***********,"account_mode" : "SINGLE","broker_redirect_uri_registered": false,"authorization_user_agent" : "WEBVIEW","authorities": [
    {
      "type": "B2C","authority_url": "SIGNIN_SIGNUP_POLICY","default": true
    },{
      "type": "B2C","authority_url": "PASSWORD_RESET_POLICY"
    }
  ]
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)