Get the Azure AD B2C Application client id in the custom policy

后端 未结 1 1364
無奈伤痛
無奈伤痛 2021-01-15 18:35

Hi the custom policy gets called with the client id of the B2C app

https://login.microsoftonline.com/TENANT/oauth2/v2.0/authorize?p=B2C_1A_POLICY&client_id=THE-

1条回答
  •  -上瘾入骨i
    2021-01-15 18:52

    Ok its a bit of a work around but I tried with a standard UserJourneyContextProvider technical profile and this didnt work

    so to get the client id as a claim I did the following

    Create an orchestration step

    
      
       
       
           
    

    Then create a RESTFUL technical profile which will call a Function App passing the OIDC with the {OIDC:ClientID}

    
        Get-ClientID-FromOIDC
        
        
         None
         --FUNCTION APP URL--
         QueryString
        
        
          
         
         
           
          
      
    

    And then finally create a function app which accepts the client id from the querystring and returns it with the correct format for B2C to identify

    using System.Net; using System.Net.Http.Formatting;

      public static async Task Run(HttpRequestMessage req, 
      TraceWriter log)
      {
           log.Info("C# HTTP trigger function processed a request.");
          // parse query parameter
          string client_id = req.GetQueryNameValuePairs()
            .FirstOrDefault(q => string.Compare(q.Key, "client_id", true) == 0)
            .Value;
    
          return req.CreateResponse(
          HttpStatusCode.OK, new ResponseContent
          {
              version = "1.0.0",
              status = (int) HttpStatusCode.OK,
              client_id = client_id
          },
          new JsonMediaTypeFormatter(), "application/json");
    
       }
    
       class ResponseContent {
         public string version;
         public int status;
         public string client_id;
     }
    

    You will now get the B2C application client_id as a claim in the claim bag so you can do what you want with it now

    0 讨论(0)
提交回复
热议问题