-
Notifications
You must be signed in to change notification settings - Fork 374
Working example with react/axios #481
Comments
Hint: You should be fetching a token before each HTTP request. Otherwise you could be working with expired tokens |
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! |
Thanks @magnuf for sharing the information. This might help people trying to use adal with react. I will close issue since this is more of an informational post. |
@magnuf thanks dude this works great even with ADFS. |
thanks for this example! I had to adjust it a little bit to use with apiSauce but it helped a lot :) |
@magnuf Thanks so much for this! After 2 weeks of stumbling in the dark this fixed it! |
Hi magnuf, 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? |
see here : https://github.com/salvoravida/react-adal |
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? |
Hi!
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.
As I have spent way too much time on this, I am making this issue so that maybe I can help someone who is struggling as well. I can't find any better place to put it. Also, if you see some errors, it would be greatly appreciated if you pointed them out :)
index.js
Auth.js. This is set as the redirectUri in the adal config.
The text was updated successfully, but these errors were encountered: