Home > Enterprise >  Azure AD B2C redirect_uri error says The redirect URI com.bol.azure_test://oauth/redirect provided i
Azure AD B2C redirect_uri error says The redirect URI com.bol.azure_test://oauth/redirect provided i

Time:12-05

I am working on a cross platform mobile app in Flutter which will be protected using Azure_AD_B2C. I am just wondering why is it so hard to have the redirect_uri match the one in Azure app with the mobile client. Here is how I got the redirect_uri setup in the Azure portal - enter image description here

And here is how I have it setup in my Flutter app -

onPressed: () async {
     print("Find Azure API Button Click");
     var queryParameters = {
         'p': "B2C_1_signupsignin",
         'client_id': "client_id",
          'nonce': 'defaultNonce',
          'redirect_uri': 'com.bol.azure_test',
           'scope': "offline_access openid",
                'response_type': "code",
                 'prompt': "login",
                  'grant_type': "authorization_code"
             };
         var uri = Uri.https(
               '{tenant}',
                '/{tenant/oauth2/v2.0/authorize',
                 queryParameters);
          var response = await http.get(uri);
                 print('Response -'   response.body);
           },

With the above code I am trying to open the signupsignin policy in a browser for authentication and return back to the app once authentication is done. Currently it is not opening the browser and the policy.

If print response.statuscode I get 200. But If I print response.body then I get the error saying the below. The redirect URI com.bol.azure_test; provided in the request is not registered for the client id {client_id;."};

I have been stuck on this for a few weeks now.

Please advise!

CodePudding user response:

Do a network trace and see what redirect URI you are sending, and compare that to what you have configured.

Make sure you are using the right clientID.

CodePudding user response:

I tried to reproduce the same in my environment and got the same error as below:

enter image description here

The error "The redirect URI XXX provided in the request is not registered for the client id" usually occurs if there is a mismatch in configuring the redirect URI in the Azure Portal and in the Flutter app.

To resolve the error, try including the redirect_uri in the Flutter app like below:

client_id': "client_id",
'nonce': 'defaultNonce',
'redirect_uri': 'msauth://com.bol.azure_test',

And in the Portal as:

enter image description here

Make sure the ClientID you are passing is valid:

enter image description here

I agree with rbrayb, if still the issue persists try running a network trace and compare the redirect_uri you are passing.

I tried to authorize by using the below endpoint:

https://testaadb2c.b2clogin.com/testaadb2c.onmicrosoft.com/<policy-name>/oauth2/v2.0/authorize
&client_id=Client_ID
&response_type=code
&redirect_uri=redirect_uri
&response_mode=query
&scope=offline_access openid
&state=12345

When I passed the valid URIs, I am able to generate the code value successfully like below:

enter image description here

If still the issue persists, Check the below:

  • Check whether you have Registered the Application the Azure AD B2C Tenant.
  • You can install Fiddler, enable HTTPS capture and the redirect_uri value and compare it in the Portal.
  • Try setting the redirect_uri as com.bol.azure_test both in Azure Portal and in the Flutter App and try.

Reference:

Flutter_azure_b2c: A flutter library to handle the Azure B2C authentication protocol by Luca Calacci

  • Related