簡體   English   中英

在自定義策略中獲取 Azure AD B2C 范圍

[英]Get the Azure AD B2C scope in the custom policy

我嘗試創建一個自定義策略,我想獲得一些聲明並將其發送到我的 REST API。 我的 API 是用電子郵件、givenName 等調用的……但是通過查詢字符串(如 client_id、resource_id 和大多數范圍)傳遞的聲明是空的。

我在這里找到了獲取 client_id 的解決方法: Get the Azure AD B2C Application client id in the custom policy

但我沒有發現關於范圍的任何信息。

這是我的 REST API 聲明提供程序:

<ClaimsProvider>
    <DisplayName>REST API</DisplayName>
    <TechnicalProfiles>
        <TechnicalProfile Id="AzureFunction-SendClaims">
            <DisplayName>Send Claims</DisplayName>
            <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
            <Metadata>
                <Item Key="ServiceUrl">https://XXXX.azurewebsites.net/api/XXXX</Item>
                <Item Key="AuthenticationType">None</Item>
                <Item Key="SendClaimsIn">Body</Item>
            </Metadata>
            <InputClaims>
                <InputClaim ClaimTypeReferenceId="givenName"/>
                <InputClaim ClaimTypeReferenceId="client_id" PartnerClaimType="clientId" DefaultValue="{OIDC:ClientId}"/>
                <InputClaim ClaimTypeReferenceId="resource_id"/>
                <InputClaim ClaimTypeReferenceId="email"/>
                <InputClaim ClaimTypeReferenceId="otherMails"/>
                <InputClaim ClaimTypeReferenceId="grant_type"/>
                <InputClaim ClaimTypeReferenceId="scope"/>
            </InputClaims>
        </TechnicalProfile>
    </TechnicalProfiles>
</ClaimsProvider>

我認為沒有辦法獲得范圍。 您可以在此處查看可從 B2C 政策中訪問的聲明和屬性列表

可以使用 OpenId 連接聲明解析器檢索范圍:

<InputClaim ClaimTypeReferenceId="Scope" DefaultValue="{OIDC:Scope}"/>

請參閱 OpenID Connect 特定聲明的文檔

在您的自定義策略中,以簡單明了的方式自由且安全地發送變量。 傳遞范圍的上下文是當您從用戶會話調用 REST API 時,因此您必須請求自定義策略令牌。

您可以通過兩種方式使用 MSAL 庫(我更喜歡這個): https ://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-web-api-call-api -acquire-token?tabs=aspnetcore

或者,通過直接調用自定義策略並在范圍部分的字符串查詢中,即

scope=openid profile offline_access https://yourtenant.onmicrosoft.com/demoapi/demo.read https://kytos.onmicrosoft.com/demoapi/demo.write

不要忘記 html 編碼范圍=openid%20profile%20offline_access%20https%3A%2F...。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM