-
I have been banging my head against the wall all day and cannot figure this out. I am registering the route and getting back the id_token but the callback function never seems to fire. I have been using the oauth_glue library as a model but I have to be missing something simple. app.py
azure.py
I'm sorry if I'm just missing something and I trying to get any information has been impossible and the documentation is less than clear so any help would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 13 replies
-
Please re-format so the code is readable. There are lots of possible issues - but possibly I didn't read it correctly - but from https://github.com/authlib/loginpass/blob/master/loginpass/azure.py |
Beta Was this translation helpful? Give feedback.
-
Sorry for my crap markdown the first time. This is azure.py:
In my app.py
I tried to include more from app.py this time since I could show the cold blocks better From what I can tell my azure_identity function should be getting added as part of the blueprint during app registration in AuthLib but when nothing prints. It seems like azure_identity isn't getting called from oauthglue. I can get a valid JWT back from the azure endpoint but it doesn't go through the azure_identity function so I just get redirected back to the login page. |
Beta Was this translation helpful? Give feedback.
-
One possible reason - or at least confusing - Flask-Security will initialize OAuth() if it isn't passed as a parameter - so in your case you are creating 2 of them - maybe that doesn't matter - but either:
The main reason to get sent back to /login is due to some OauthError or MismatchingStateError (from the oauth library). There isn't a great way to display any error like this - if you have an IDE and can set a breakpoint - that might help (in flask_security::oauth_glue:oauth_response. (or maybe better - set a breakpoint over in authorize_access_token() in authlib I'll look into some way to help debug this... |
Beta Was this translation helpful? Give feedback.
-
In your browser you should see the redirect to /login/oauthresponse/azure |
Beta Was this translation helpful? Give feedback.
-
Looking at authlib:FlaskOauth2App:authorize_access_token - which is what Flask-Security uses - looks like there should be both a 'code' and a 'state' returned - a 'code=0' doesn't seem right at all. When you say the JWT is correct - at what point/where are you seeing that? I use PyCharm - works pretty well and has easy debugging built in. |
Beta Was this translation helpful? Give feedback.
-
I can try to get it working on my end - though I am not familier with azure... |
Beta Was this translation helpful? Give feedback.
-
How are you registering your app with azure? from the 'app registrations' service or some other way? |
Beta Was this translation helpful? Give feedback.
-
Ok - I have it working in my oauth example code. My config:
Of course that is MY tenant ID. I have AZURE_CLIENT_ID and AZURE_CLIENT_SECRET in the environment. I conditionally register it:
The one thing that is really a pain - and I need to look into it more - is that Azure require the redirect URL to match - INCLUDING any query params (such as next-xxx) - That makes it less than useful IMHO - but here is my redirect url configured at Azure:
Note that when this was configured incorrectly I got pop-ups from Microsoft telling me the issue. |
Beta Was this translation helpful? Give feedback.
-
Try not setting SESSION_COOKIE_SAMESITE - I have had some issues with that affecting the oauth redirect |
Beta Was this translation helpful? Give feedback.
-
Great - and this ONLY seems to matter the first time - I believe now that you have 'approved' it - you can set it back to strict and it will work. I have not spent time figuring out why except that authlib stores the state in the session - so if the session cookie isn't sent - then you will get that state error. |
Beta Was this translation helpful? Give feedback.
Try not setting SESSION_COOKIE_SAMESITE - I have had some issues with that affecting the oauth redirect