Auzure AD B2C for Authentication and Authorization
Hi All, I am trying to set up auth with Azure AD. After a successful login on Azure AD B2C, I am redirected back to the login page unless I refresh and then I am redirected to the Dashboad page.
15 Replies
Hey @.dark.energy 👋,
I am glad to see you ⚡️
Check the auth status in the checkAuth function of the authProvider. If user logged in you can return with "Promise.resolve".
There is a similar implementation for supabase
https://github.com/refinedev/refine/blob/next/examples/dataProvider/supabase/src/App.tsx#L94
GitHub
refine/App.tsx at next · refinedev/refine
Build your React-based CRUD applications, without constraints. - refine/App.tsx at next · refinedev/refine
ratty-blush•2y ago
Thanks @Omer I am doing that but seems like checkAuth doesn't get called after a successful redirect. Msal.js has events that you can hook into where set the activeaccount.
msal callback
Can you add "console.log" at the top of checkAuth?
You can also check our Auth0 example, it works similarly
https://github.com/refinedev/refine/blob/next/examples/authProvider/auth0/src/App.tsx#L36
https://refine.dev/docs/examples/auth-provider/auth0/
ratty-blush•2y ago
I have followed the Auth0 example.
ratty-blush•2y ago
![No description](https://cdn.answeroverflow.com/1032940624187490304/Screenshot_2022-10-21_at_14.25.47.png)
ratty-blush•2y ago
Now, if I were to refresh this screen, then I get redirected to Dashboard
Probably returning
Promise.reject
from "checkAuth" after redirect. You should wait for the result of the "acquireTokenSilent" and "acquireTokenPopup" async functions.
Could you try like this
ratty-blush•2y ago
Okay
I needed an else in if otherwise it was going straight to Dashboard
But this leads to the same behaviour
Could you try this?
if it doesn't work i will try to create an example
ratty-blush•2y ago
Not working
Can I follow this tutorial?
https://learn.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-react
Tutorial: Create a React single-page app that uses auth code flow -...
In this tutorial, you create a React SPA that can sign in users and use the auth code flow to obtain an access token from the Microsoft identity platform and call the Microsoft Graph API.
ratty-blush•2y ago
Is it possible to share information with me via private message? I can quickly skip the setup steps.
REACT_APP_AZURE_AAD_CLIENT_ID, REACT_APP_AZURE_AAD_TENANT_NAME etc
ratty-blush•2y ago
Sure
Thank you! 🎉
Ok I found the problem. Could you try this?