-
Notifications
You must be signed in to change notification settings - Fork 53
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
missing "mail" in response with Microsoft SSO #81
Comments
I investigated this further and .... well let's just say MicrosoftSSO has no error handling what-so-ever. I might submit a PR at some point if I get it to work. If you need a patch straight away, put this in the top of from fastapi_sso.sso.base SSOLoginError
error = response.get("error")
if error:
raise SSOLoginError(401, f"Error '{pprint.pformat(error)}' returned from Microsoft") |
I believe some tenants require to ask for Could you test if this resolves the problem for you? |
I did not test your suggestion, but it is aligning well with what I found what worked for me in the end; to omit the scope parameter from MicrosoftSSO constructor altogether. I used to have it set to ["openid"] which would override the default of ["openid", "User.Read"]. It could also just be luck/timing of the 10 times I created and changed my application settings and credentials inside Azure...
I guess just providing an example/documentation would solve this issue.
Anyways, thanks for looking at my issue!
|
That's a good idea, I've added a simple post to guide users who struggle with this as well, thanks! https://tomasvotava.github.io/fastapi-sso/how-to-guides/key-error/ |
The key error of the OP is not a problem anymore. But still, I don't get an email address. Even with the scopes
Resulting in:
Interestingly, my mail address is contained in the field userPrincipalName. |
Hi @bolau! I am afraid since e-mail is really considered personal data these days, more and more openid providers will make it more difficult to retrieve it on behalf of a user. E.g. Apple has a configuration that allows the user to generate a temporary e-mail for each service, therefore you'll never actually be able to retrieve the user's real e-mail address and won't even be able to tell. Nevertheless, I believe in Microsoft's case there are lots of settings on tenant level that can play part in whether you get the e-mail address or not. @app.get("/callback")
async def login_callback(request: Request):
with sso:
openid = await sso.verify_and_process(request)
print(sso.access_token) Then you can use the access token to play around with the API in curl / Postman or MS Graph Explorer. In the explorer, you can provide your own access token (obtained with fastapi) and try to come up with a combination of fields and params that will yield what you need. I will play around as well, but in my tenant and my app, the mail field is actually retrieved, so it's hard for me to debug. |
Hi Tomas, thanks for your reply. I tried the Graph Explorer, but couldn't get the email address out of it.
I don't want to make this a pull request though, since this is most likely not a "correct" solution. I guess my account just doesn't have a proper e-mail address linked to it. Which seems weird, but anyhow :) |
In that case, you could try passing |
I have set up an application in Azure with credentials.
When I try to log in using said credentials as per the examples, the call fails with a missing key error:
The code looks like this:
The text was updated successfully, but these errors were encountered: