Share via


Een aangepast OAuth2-fout technisch profiel definiëren in een aangepast Azure Active Directory B2C-beleid

In dit artikel wordt beschreven hoe u een aangepaste OAuth2-fout kunt afhandelen met Azure Active Directory B2C (Azure AD B2C). Gebruik dit technische profiel als er iets fout gaat in uw beleid. Het technische profiel retourneert een fout naar uw OAuth2- of OpenId Connect Relying Party-toepassing. Bekijk de livedemo van het technische OAuth2-profiel voor aangepaste fouten.

Aangepast OAuth2-foutbericht afhandelen:

  1. Definieer een technisch OAuth2-foutprofiel.
  2. Stel de foutcode en foutberichtclaims in.
  3. Roep vanuit het gebruikerstraject het technische OAuth2-foutprofiel aan.

OAuth2-fout

De fout wordt geretourneerd met de volgende gegevens:

  • Fout - access_denied
  • error_description : het foutbericht met behulp van de conventie AAD_Custom_<errorCode>: <errorMessage>.
  • Correlatie-id: de Azure AD B2C-correlatie-id.
  • Timestamp : het tijdstempel van de fout.

In het volgende voorbeeld ziet u een aangepast foutbericht dat wordt geretourneerd naar de https://jwt.ms app:

https://jwt.ms/#error=access_denied&error_description=AAD_Custom_1234%3a+My+custom+error+message%0d%0aCorrelation+ID%3a+233bf9bd-747a-4800-9062-6236f3f69a47%0d%0aTimestamp%3a+2021-03-25+14%3a01%3a23Z%0d%0a

Protocol

Het kenmerk Naam van het element Protocol moet worden ingesteld op OAuth2. Stel het element OutputTokenFormat in op OAuth2Error.

In het volgende voorbeeld ziet u een technisch profiel voor ReturnOAuth2Error:

<!--
 <ClaimsProviders> -->
  <ClaimsProvider>
    <DisplayName>Token Issuer</DisplayName>
    <TechnicalProfiles>
      <TechnicalProfile Id="ReturnOAuth2Error">
        <DisplayName>Return OAuth2 error</DisplayName>
        <Protocol Name="OAuth2" />
        <OutputTokenFormat>OAuth2Error</OutputTokenFormat>
        <CryptographicKeys>
          <Key Id="issuer_secret" StorageReferenceId="B2C_1A_TokenSigningKeyContainer" />
        </CryptographicKeys>
        <InputClaims>
          <InputClaim ClaimTypeReferenceId="errorCode" />
          <InputClaim ClaimTypeReferenceId="errorMessage" />
        </InputClaims>
      </TechnicalProfile>
    </TechnicalProfiles>
  </ClaimsProvider>
<!--
</ClaimsProviders> -->

Invoerclaims

Het element InputClaims bevat een lijst met claims die nodig zijn om een OAuth2-fout te retourneren.

ClaimReferenceId Vereist Beschrijving
errorCode Yes De foutcode.
Errormessage Yes Het foutbericht.

Cryptografische sleutels

Het element CryptographicKeys bevat de volgende sleutel:

Kenmerk Vereist Beschrijving
issuer_secret Yes Een X509-certificaat (RSA-sleutelset). Gebruik de sleutel die u configureert in Aan de B2C_1A_TokenSigningKeyContainerslag met aangepast beleid.

Het technische profiel aanroepen

U kunt het technische OAuth2-foutprofiel aanroepen vanuit een gebruikerstraject of subtraject (type transfer). Stel het indelingsstaptype in op SendClaims met een verwijzing naar uw technische OAuth2-foutprofiel.

Als uw gebruikerstraject of subtraject al een andere indelingsstap SendClaims heeft, stelt u het DefaultCpimIssuerTechnicalProfileReferenceId kenmerk in op het technische profiel van de tokenverlener.

In het volgende voorbeeld:

  • Het gebruikerstraject SignUpOrSignIn-Custom stelt de DefaultCpimIssuerTechnicalProfileReferenceId in op het technische profiel JwtIssuervan de tokenverlener.
  • Met de achtste indelingsstap wordt gecontroleerd of de errorCode bestaat. Zo ja, roep dan het ReturnOAuth2Error technische profiel aan om de fout te retourneren.
  • Als errorCode deze niet bestaat, geeft de negende indelingsstap het token uit.
<UserJourney Id="SignUpOrSignIn-Custom" DefaultCpimIssuerTechnicalProfileReferenceId="JwtIssuer">
  <OrchestrationSteps>
    ...
    <OrchestrationStep Order="8" Type="SendClaims" CpimIssuerTechnicalProfileReferenceId="ReturnOAuth2Error">
      <Preconditions>
        <Precondition Type="ClaimsExist" ExecuteActionsIf="false">
          <Value>errorCode</Value>
          <Action>SkipThisOrchestrationStep</Action>
        </Precondition>
      </Preconditions>
    </OrchestrationStep>

    <OrchestrationStep Order="9" Type="SendClaims" CpimIssuerTechnicalProfileReferenceId="JwtIssuer" />

  </OrchestrationSteps>
  <ClientDefinition ReferenceId="DefaultWeb" />
</UserJourney>

Volgende stappen

Meer informatie over UserJourneys