5
votes

I did this azure ad b2c web api tutorial that get's an authorization token with postman and sends it to the API. But how do I get an authorization token from a react native app? When I create the application, do I choose 'Web App / Web API' or 'Native client'? And is there any examples / resources that I can use? Can I use this sample with Microsoft Authentication Library (MSAL)? Im confused because react native is built with JS but compiled to native code.

2
When you have the question of Web app / API or native, you need to ask this question from yourself: Does this app run on the user's device? If the answer is yes, then the app is native. - juunas
A React Native app is native. - juunas
I'm currently facing the same problem - did you find any solution? - niceman
no i didn't. :/ - thatsIT
Hey @thatsIT check this and let me know if it works for you: github.com/wkh237/react-native-azure-ad - Andres Elizondo

2 Answers

2
votes

Check https://github.com/GSingh01/ad-b2c-react-native. It uses latest spec from Microsoft and JS based solution thus you don't need to eject from expo.

1
votes

Assuming you plan to use the login from you RN App to both validate the user is valid and to then request data over Azure hosted API endpoints, you should setup your AD B2C Application to allow both Web\Web API AND Native Client.

If you are OK with using the web-based login from your App which jumps out to the mobile browser and then back to your app, have a look at Visual Studio App Center Auth.

NOTE: App Center Auth has been retired: https://devblogs.microsoft.com/appcenter/app-center-mbaas-retirement/

If you wish to use your own screens hosted in your RN App, you then will need to follow a JWT authentication example. Details of that would be a separate question though.