-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug?]: Azure Active Directory Authentication – Redirect to authorization endpoint despite @skipAuth #7112
Comments
@m3t Can you reproduce this in a fresh 3.6.1 installation? |
@jeliasson |
@m3t I saw that earlier, and it has references from 0.45.0. Have you tried from a fresh out-of-the-box installation of 3.6.1? |
@jeliasson |
@jeliasson |
@jeliasson I've installed it with following versions and commands : # Node: 16.14.2
# Yarn: 3.2.3
# @redwoodjs/core: 3.6.1
yarn create redwood-app --ts ./redwood-demo
yarn rw setup auth azureActiveDirectory |
@m3t Thanks for that! By any chance you can share a temporary Azure App registration and it's environment variables that could be used for troubleshooting? Ideally, the redirect URIs would include http://localhost:8910 😊 @Tobbe Without diving too deep into the issue at hand, do you know why a anonymous request to GraphQL with the |
@jeliasson |
We are experiencing in the same problem. Did anyone find a solution or a workaround? |
Short update: I was able to reproduce the behavior with
(Thanks for all the work you did there @Tobbe.) |
Hi @jeliasson and @Tobbe , |
Have you tried out the login data I gave you? |
@m3t Thank you for the reproduction repo. I totally misunderstood what the error was until I ran your code and saw the issue with my own eyes. So, what's happening is that as soon as you load HomePage the Because of this, no matter what kind of query/mutation you do, Redwood will always ask the auth provider client sdk for a token. And apparently, when it does, the Azure sdk will trigger the login screen. |
Looking into the The error it throws when it fails is
I'm afraid this is as far as I can take this on my own. @jeliasson do you think we can come up with a more clever way of determining if we should fall back to |
@Tobbe Agreed, we need to add some logic for choosing a path if we get an exception from We should work on this in the now decoupled auth package Docs
|
We're releasing v4 Wednesday next week unless something unforeseen comes up. But the change you're suggesting doesn't sound like a breaking change, so it can come in whenever and will just be included in the next release whichever one that might be. So if we fix it in the next few days it'll be in v4. Otherwise it'll be included in v4.1 (which we already have lined up for releasing Vite support) I'll have a look at those docs and see if I can come up with something |
Untested, but reading the docs it looks like something along these lines should catch all possibilities. But it sure is ugly :( getToken: async (options?: SilentRequest) => {
// Default scopes if options is not passed
const request = options || {
scopes: ['openid', 'profile'],
}
// The recommended call pattern is to first try to call
// acquireTokenSilent, and if it fails with an
// InteractionRequiredAuthError, call acquireTokenRedirect
// https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/acquire-token.md
// NOTE: We are not catching the `InteractionRequiredAuthError`,
// perhaps we can branch off `error.name` if this strategy doesn't work
// properly.
try {
const token = await azureActiveDirectoryClient.acquireTokenSilent(
request
)
return token.idToken
} catch (err) {
if (
err instanceof InteractionRequiredAuthError ||
(err instanceof AuthError &&
(err.name === 'InteractionRequiredAuthError' ||
err.errorCode === 'consent_required' ||
err.errorCode === 'interaction_required' ||
err.errorCode === 'login_required'))
) {
// fallback to interaction when silent call fails
return azureActiveDirectoryClient.acquireTokenRedirect(request)
}
}
return null
}, Does anyone know how I can force/trigger an |
These docs mentions extracting claims from the error and injecting into // extract, if exists, claims from error message
if (error.ErrorMessage.claims) {
request.claimsRequest = JSON.stringify(error.ErrorMessage.claims);
} The errors I get when I try that code are
|
This works
So I don't see why |
I did the simplest implementation I could think of in #7386 |
@Tobbe Thank you so much for this! |
I'm also working on some doc updates #7387 |
Hi @Tobbe, a quick question: If you confirm that this is a bug I will open a new issue. |
While we have a few Azure AD users in this issue; any of you have issues with iOS/Safari? |
Thanks. @jtoar This is very helpful. It seems like the behavior is the same as for dbAuth. As multiple requests after on interaction do not get a new token. Then I leave it as it is for now. And come back to it if I think we need to optimize for those 100-150ms. |
@jeliasson Tested with Safari on macos and ios and did not have any problems! |
Just a follow up for anyone that might stumble upon this later; |
What's not working?
@jeliasson @Tobbe
When Azure Active Directory Authentication is integrated as
AuthProvider
, I get a redirect right away to the authorization endpoint only by using a public query.So far, this is my understanding for the login process:
How do we reproduce the bug?
Version 3.6.1
yarn create
)What's your environment? (If it applies)
Are you interested in working on this?
The text was updated successfully, but these errors were encountered: