azure-ad-b2cazure-ad-b2c-custom-policy

How to troubleshoot RESTful endpoint response in custom policy?


I am trying to get the groups that a certain user belongs to in their sign-in journey.

I am using calling RESTful graph API for that.

Here are my Technical Profiles, the idea is to get token for my graph API app and use the token to do a /getMemberGroups call to get the groups as StringCollection:

<ClaimsProvider>
    <DisplayName>Get user groups of a certain user</DisplayName>
    <TechnicalProfiles>
      <TechnicalProfile Id="GetAccessTokenForGraphApi">
        <DisplayName></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://login.microsoftonline.com/{tenant_name}.onmicrosoft.com/oauth2/v2.0/token</Item>
          <Item Key="AuthenticationType">Basic</Item>
          <Item Key="SendClaimsIn">Form</Item>
        </Metadata>
        <CryptographicKeys>
          <Key Id="BasicAuthenticationUsername" StorageReferenceId="B2C_1A_userMgntAppId" />
          <Key Id="BasicAuthenticationPassword" StorageReferenceId="B2C_1A_userMgntAppClientSecret" />
        </CryptographicKeys>
        <InputClaims>
          <InputClaim ClaimTypeReferenceId="grant_type" DefaultValue="client_credentials" />
          <InputClaim ClaimTypeReferenceId="scope" DefaultValue="https://graph.microsoft.com/.default" />
        </InputClaims>
        <OutputClaims>
          <OutputClaim ClaimTypeReferenceId="bearerToken" PartnerClaimType="access_token" />
        </OutputClaims>
        <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
      </TechnicalProfile>
      <TechnicalProfile Id="GetUserGroups">
        <DisplayName>Retrieves security groups assigned to the user</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://graph.microsoft.com/v1.0/users/{objectId}/getMemberGroups</Item>
          <Item Key="AuthenticationType">Bearer</Item>
          <Item Key="UseClaimAsBearerToken">bearerToken</Item>
          <Item Key="SendClaimsIn">Body</Item>
          <Item Key="AllowInsecureAuthInProduction">true</Item>
          <Item Key="ClaimUsedForRequestPayload">securityEnabledOnly</Item>
          <Item Key="DefaultUserMessageIfRequestFailed">Cannot process your request right now, please try again later.</Item>
        </Metadata>
        <InputClaims>
          <InputClaim Required="true" ClaimTypeReferenceId="objectId" />
          <InputClaim Required="true" ClaimTypeReferenceId="bearerToken" />
          <InputClaim Required="true" ClaimTypeReferenceId="securityEnabledOnly" DefaultValue="false" AlwaysUseDefaultValue="true" />
        </InputClaims>
        <OutputClaims>
          <OutputClaim ClaimTypeReferenceId="groups" PartnerClaimType="value" />
        </OutputClaims>
        <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
      </TechnicalProfile>
    </TechnicalProfiles>
  </ClaimsProvider>

The GetAccessTokenForGraphApi TP is working fine and I can get the bearerToken output claim if I call it solely in my userJourney.

However, when I put GetUserGroups TP as next orchestration step, I have this sort of exception in my application insight log:

{
    "Kind": "HandlerResult",
    "Content": {
      "Result": true,
      "RecorderRecord": {
        "Values": [
          {
            "Key": "SendErrorTechnicalProfile",
            "Value": "OpenIdConnectProtocolProvider"
          },
          {
            "Key": "Exception",
            "Value": {
              "Kind": "Handled",
              "HResult": "80131500",
              "Message": "Cannot process your request right now, please try again later.",
              "Data": {
                "IsPolicySpecificError": false
              },
              "Exception": {
                "Kind": "Handled",
                "HResult": "80131500",
                "Message": "Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details.",
                "Data": {}
              }
            }
          }
        ]
      },

I believe there is some error when calling the RESTful endpoint. My question is, how I can "visualize" the restful call to see what I actually send out? For example, as you can see I am putting objectId in my URL, seeing the actual URL would be useful to troubleshoot the restful call.

Kindly let me know if more information I need to supplement. Many thanks in advance!


Solution

  • You can't do this: <Item Key="ServiceUrl">https://graph.microsoft.com/v1.0/users/{objectId}/getMemberGroups</Item>

    And this in combination: <Item Key="SendClaimsIn">Body</Item>

    You can either send claims in URL, where your claim resolver will resolve the objectId, or you send claims in body. https://learn.microsoft.com/en-us/azure/active-directory-b2c/restful-technical-profile#metadata

    That is why your call fails.

    You need to call your own API, and then have your own API call Graph API.