Network Request Failed Error when fetching token in Azure B2C

sagar setu 96 Reputation points
2021-01-25T18:08:09.833+00:00

Hello,

I have been trying to integrate authorization and authentication using azure ad b2c in a react native app. I am successfully able to get the authorization code, but the trying to get the access tokens results in 'Network Request Failed' error.

I am using fetch() to make HTTP (https) request which have been constructed according to the details here - https://learn.microsoft.com/en-us/azure/active-directory-b2c/authorization-code-flow
If I copy and paste the url I am passing to fetch() in a browser, it returns a response with access token. However, the same url throws error in the react native fetch().

I have double checked that it is not an issue with fetch() itself. I am able to call some public APIs on https and get the expected response. So the url works in a browser, and fetch() woks in the app, but the url and fetch do not work together in the app.

Any clues as to how to solve this would be appreciated.

Thanks!

EDIT:
Platform: Android
Tried the exact same code in a separate JS environment reusing a recently obtained authorization code, and it returns the token too. So there shouldn't be any issue in the fetch statement.

Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,908 questions
0 comments No comments
{count} votes

Accepted answer
  1. sagar setu 96 Reputation points
    2021-01-25T19:49:05.743+00:00

    Looking into android studio logcat told me that the issue was conflicting version of different okHttp modules. Forced the same version for different modules and fetch worked. Still need to understand why it worked on simple GET calls but not the POST call to azure ad b2c. However, this fixed it for now and I am able to fetch the tokens.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.