【问题标题】:Is there a way to validate custom attribute in ROPC Flow before sending tokens?有没有办法在发送令牌之前验证 ROPC Flow 中的自定义属性?
【发布时间】:2020-07-31 18:33:43
【问题描述】:

所有用户都有一个用户属性“extension_isApproved”。他们只有在设置为 True 时才能登录或接收令牌。但是,我无法弄清楚如何在 ROPC 流程中执行此操作。我想要的行为是,如果请求令牌的用户未获批准,则发回一条错误消息。

我从https://github.com/Azure-Samples/active-directory-b2c-custom-policy-starterpack/blob/master/scenarios/source/aadb2c-ief-ropc/TrustFrameworkExtensions.xml 找到的基本模板开始

有我的代码(我已经尝试了一些限制用户的方法,但它不起作用):

<TechnicalProfile Id="ResourceOwnerPasswordCredentials-OAUTH2">
      <DisplayName>Local Account SignIn</DisplayName>
      <Protocol Name="OpenIdConnect" />
      <Metadata>
        <Item Key="UserMessageIfClaimsTransformationBooleanValueIsNotEqual">You are not approved. Contact your administrator for approval.</Item>
        <Item Key="UserMessageIfClaimsPrincipalDoesNotExist">We can't seem to find your account</Item>
        <Item Key="UserMessageIfInvalidPassword">Your password is incorrect</Item>
        <Item Key="UserMessageIfOldPasswordUsed">Looks like you used an old password</Item>
        <Item Key="DiscoverMetadataByTokenIssuer">true</Item>
        <Item Key="ValidTokenIssuerPrefixes">https://sts.windows.net/</Item>
        <Item Key="METADATA">https://login.microsoftonline.com/{tenant}/.well-known/openid-configuration</Item>
        <Item Key="authorization_endpoint">https://login.microsoftonline.com/{tenant}/oauth2/token</Item>
        <Item Key="response_types">id_token</Item>
        <Item Key="response_mode">query</Item>
        <Item Key="scope">email openid</Item>
      </Metadata>
      <InputClaims>
        <InputClaim ClaimTypeReferenceId="logonIdentifier" PartnerClaimType="username" Required="true" DefaultValue="{OIDC:Username}"/>
        <InputClaim ClaimTypeReferenceId="password" Required="true" DefaultValue="{OIDC:Password}" />
        <InputClaim ClaimTypeReferenceId="grant_type" DefaultValue="password" />
        <InputClaim ClaimTypeReferenceId="scope" DefaultValue="openid" />
        <InputClaim ClaimTypeReferenceId="nca" PartnerClaimType="nca" DefaultValue="1" />

        <InputClaim ClaimTypeReferenceId="client_id" DefaultValue="{Settings:ProxyIdentityExperienceFrameworkAppId}" />
        <InputClaim ClaimTypeReferenceId="resource_id" PartnerClaimType="resource" DefaultValue="{Settings:IdentityExperienceFrameworkAppId}" />
      </InputClaims>
      <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="oid" />
        <OutputClaim ClaimTypeReferenceId="userPrincipalName" PartnerClaimType="upn" />
      </OutputClaims>
      <OutputClaimsTransformations>
        <OutputClaimsTransformation ReferenceId="CreateSubjectClaimFromObjectID" />
      </OutputClaimsTransformations>
      <ValidationTechnicalProfiles>
        <ValidationTechnicalProfile ReferenceId="AAD-UserReadUsingObjectId" />
        <ValidationTechnicalProfile ReferenceId="ClaimsTransformation-AssertIsApproved" />
      </ValidationTechnicalProfiles>
      <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
    </TechnicalProfile>

<ClaimsProvider>
  <DisplayName>Session Management</DisplayName>
  <TechnicalProfiles>
    <TechnicalProfile Id="SM-RefreshTokenReadAndSetup">
      <DisplayName>Trustframework Policy Engine Refresh Token Setup Technical Profile</DisplayName>
      <Protocol Name="None" />
      <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="objectId" />
        <OutputClaim ClaimTypeReferenceId="refreshTokenIssuedOnDateTime" />
      </OutputClaims>
      <ValidationTechnicalProfiles>
        <ValidationTechnicalProfile ReferenceId="AAD-UserReadUsingObjectId" />
        <ValidationTechnicalProfile ReferenceId="ClaimsTransformation-AssertIsApproved" />
      </ValidationTechnicalProfiles>
    </TechnicalProfile>
  </TechnicalProfiles>
</ClaimsProvider>

<ClaimsTransformation Id="AssertIsApproved" TransformationMethod="AssertBooleanClaimIsEqualToValue">
    <InputClaims>
      <InputClaim ClaimTypeReferenceId="extension_isApproved" TransformationClaimType="inputClaim" />
    </InputClaims>
    <InputParameters>
      <InputParameter Id="valueToCompareTo" DataType="boolean" Value="true" />
    </InputParameters>
  </ClaimsTransformation>

其余代码与涉及 ROPC 流程的基本模板相同。

【问题讨论】:

    标签: azure azure-ad-b2c


    【解决方案1】:

    ROPC 在需要用户交互的身份验证流程出现任何中断时不起作用。例如,当密码已过期或需要更改时,需要进行多因素身份验证,或者在登录过程中需要收集更多信息时(例如,用户同意)。 参考这个链接:https://docs.microsoft.com/en-us/azure/active-directory-b2c/configure-ropc?tabs=app-reg-ga

    【讨论】:

    • 再次感谢 Rohit 抽出宝贵时间。但是,它没有任何用户交互。它只需要验证一个自定义属性(如果设置为 true 或 false),然后决定拒绝或接受发送令牌。由此,我不知道您在哪里看到了用户交互。
    • 只有自我断言的技术配置文件才能使用验证技术配置文件。 AssertBooleanClaimIsEqualToValue 转换只能在用作验证技术配置文件时运行。我尝试过的场景:(我只是尝试实施策略,而不是与应用程序集成) 1. 此解决方案的第 4 步stackoverflow.com/questions/63141778/…。唯一的问题是它会给出状态码 200 但不共享令牌。 2.您可以在注册期间禁用该帐户(accountEnabled=false)。使用 400 代码给出 error_denied。
    • 好的,我明白了。由于不可能,我想在正文中返回带有令牌的“extension_isApproved”,以便可以在另一侧进行验证。有办法吗?
    • 我找到了如何将“isApproved”放入 id_token 中。但是有没有办法直接在正文中而不是在令牌中发送?
    • 我没有得到你想要的东西。
    【解决方案2】:

    最后,我们所做的就是在技术简介中添加&lt;OutputClaim ClaimTypeReferenceId="extension_isApproved" /&gt; ROPC_Auth.xml

    通过这样做,您将在调用 ROPC 流时直接在响应的 id_token 中收到自定义属性。

    我们联系了 Microsoft 支持,他们告诉我们,我们最初想要做的方式(通过阻止用户并返回错误)对他们来说太先进了,他们不知道该怎么做,甚至不知道该怎么做是可能的。

    【讨论】:

      猜你喜欢
      • 2021-02-22
      • 1970-01-01
      • 2016-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 2022-09-27
      相关资源
      最近更新 更多