I want to implement the Cognito Hosted UI for some users in my Django application. I have successfully been able to redirect the users to the desired url for authentication using the following:
return redirect(https://....amazoncognito.com/oauth2/authorize?client_id=....redirect_uri=localhost).
I am able to successfully authenticate and redirect back to my localhost where the url in the browser is localhost/?code=xyz. I do not understand how I can retrieve this code xyz back in python to perform next steps? I see that in the Django Terminal that it reads the required code. This is what the terminal shows:
[04/May/2022 16:08:15] "POST /login HTTP/1.1" 302 0
[04/May/2022 12:09:04] "GET /?code=xyz HTTP/1.1" 200 8737
I just do not know how to get this code xyz in my views.py so that I can continue the login. I tried variations of request.GET that did not work.
Any help is appreciated!!
CodePudding user response:
I just figured it out 5 days later (what 5 days of not looking at your code can do!)
request.GET.get(‘code’) gives back the 'xyz' that shows up in the url in the browser.
