连接两个自定义策略

时间:2021-04-08 19:50:04

标签: azure-ad-b2c azure-ad-b2c-custom-policy

我已经实现了 custom-mfa-totp 示例。我定义了一个允许重置二维码的自定义策略。一切正常。

现在我需要让我们说连接这两个策略。让我们假设以下场景:

  • 用户注册我的 B2C
  • 用户登录后,必须安装身份验证应用才能获取验证码
  • 用户已登录
  • 一个月后,用户必须重新安装应用程序(出于未知原因)。如果他去登录,就会要求一个验证码:

enter image description here

我的想法是添加一种链接,以便打开另一个重置二维码的策略。在文档中,我看到了添加 Action 的可能性,但我还没有弄清楚如何添加。 有什么提示吗?

我已经添加了:

enter image description here

但为了以正确的方式重定向,我需要上一页的参数,例如‘client_Id’和redirect_url

2 个答案:

答案 0 :(得分:1)

假设您已经知道如何 customize the UI,您可以将 ContentDefinitionParameters 添加到您的依赖方策略以将参数传递给您的 HTML 模板。您可以使用 claim resolvers 获取 client_id 和 redirect_uri:

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/main_screen_image"
    android:fitsSystemWindows="true"
    tools:context=".HomeScreen"
    tools:openDrawer="start">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/purple_200"
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        <!--Dark text
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"-->

        <!--        Container for fragments-->
        <!--<FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />-->

    </LinearLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_menu" />

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="20dp">

        <ImageView
            android:id="@+id/homeScreenLogo"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_gravity="center"
            android:src="@drawable/kaznau_logo"
            app:layout_constraintBottom_toTopOf="@+id/guideline6"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.498"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.4"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline6">

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnAboutUniversity"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_university"
                android:text="@string/s_about_kaznau"
                app:cornerRadius="5dp" />

            <View
                android:layout_width="0dp"
                android:layout_height="20dp"
                android:layout_weight="1" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnFaculties"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_faculty"
                android:text="@string/s_faculty"
                app:cornerRadius="5dp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout">

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnNews"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_baseline_article_24"
                android:text="@string/s_news"
                app:cornerRadius="5dp" />

            <View
                android:layout_width="0dp"
                android:layout_height="20dp"
                android:layout_weight="1" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnEvents"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_baseline_event_24"
                android:text="@string/events_name"
                app:cornerRadius="5dp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout2">

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnLocations"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_location"
                android:text="@string/s_locations"
                app:cornerRadius="5dp" />

            <View
                android:layout_width="0dp"
                android:layout_height="20dp"
                android:layout_weight="1" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnCampus"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_campus"
                android:text="@string/s_campus"
                app:cornerRadius="5dp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout3">

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnLinks"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_links"
                android:text="@string/s_links"
                app:cornerRadius="5dp" />

            <View
                android:layout_width="0dp"
                android:layout_height="20dp"
                android:layout_weight="1" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnContacts"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_contacts"
                android:text="@string/s_contacs"
                app:cornerRadius="5dp" />
        </LinearLayout>

        <com.google.android.material.button.MaterialButton
            android:id="@+id/btnAgrodamu"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_gravity="center"
            android:text="@string/s_agrodamu"
            app:cornerRadius="5dp"
            app:layout_constraintBottom_toTopOf="@+id/guideline7"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.555"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout4"
            app:layout_constraintVertical_bias="0.164" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_begin="20dp"
            app:layout_constraintGuide_percent="0.4" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_begin="20dp"
            app:layout_constraintGuide_percent="0.9" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout>

可以通过 JavaScript 解析来自 <ContentDefinitionParameters> <Parameter Name="client_id">{OIDC:ClientId}</Parameter> <Parameter Name="redirect_uri">{OIDC:RedirectUri}</Parameter> </ContentDefinitionParameters> 的查询字符串来访问这些值。当 Identity Experience Framework 加载相应的内容定义时,会将 SETTINGS.remoteResource 对象注入到您的 HTML 模板中。请注意,SETTINGS 对象是内部 API 的一部分,可能会在 page layout versions 之间发生变化。

既然您有了 client_id 和 redirect_uri,您就可以使用 JavaScript 生成指向另一个政策的链接,尽管在政策重定向中包含原始随机数也可能是一个好主意。

答案 1 :(得分:-1)

您可以在自定义 HTML 中添加指向 myapp.com/launchPolicyX 的链接。然后应用程序应该使用您最喜欢的 OpenId 库发出新的身份验证请求。