Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Working example with react/axios #481
I have finally managed to get adal.js up and running (I think), with reauthenticating after token timeout as well. With a .net backend hosted in azure. This is done in a react environment, using axios for running requests.
Auth.js. This is set as the redirectUri in the adal config.
The interceptor is there to catch any expired tokens. I guess it's perhaps a matter of taste if you want to fetch the token before each request, or wait until you get a 401 to fetch a new one. I first tried with fetching it before each call, but I figured that would lead to a lot of unnecessary fetchings, since it would only need to fetch it once for each time it expires instead.
Working with an expired token isn't a problem in itself, as long as you catch it, and retry with a renewed token, is the way I see it at least :)
Thanks for the feedback!
I have to integrate ESO authentication in my application. My application's front-end is in react and back-end is in node.
Requirement : when user hits the UI url, it should redirect to ESO url to check the authentication for that user. If the user is authenticated then home page should load in the UI.
Thanks in advance.
@magnuf thank you, this script has been very helpful in getting AD SSO up and running smoothly. I do have a recommendation:
If you've been blessed to support IE11 / Edge then you'll find that you get a consistent "Invalid Calling Object" error when trying to log in using the above code. After spending all afternoon tearing my hair out I've found the problem to be right here
Replace it with
I am not 100% sure why the Microsoft browsers have trouble with setting the function directly as opposed to wrapping it (maybe it's their implementation of console.log and can only take so many params?).
Where does renewal of the access token for the React SPA take place with the above setup? If I'm correct, the Axios intercepter renews access tokens for the API backend resource right? I'm having issues with renewing access tokens for the React frontend.
I saw the code to put in index.js but since its a SPA, index gets loaded only once.
Or am I missing something completely here? I'm using a React SPA with OAuth2 Implicit Flow (oauth2AllowImplicitFlow specified in manisfest in AAD) with a REST API backend (clientID of SPA added to knownClientApplications) protected with BearerStrategy.
I'm using two access tokens, one for the React SPA and one for the backend API, is that the way to go?
This is exactly what I am looking for, my setup is as follows, I bought a react template and I already integrated it with Azure AD Authentication using the above package provided by @salvoravida .
After logging in, however I will need to call REST APIs that will be secured with Azure AD.
I do have a question.
Is there another way to contact you if I have issues, or everything should be done through this issue?