How to get the code returned by Cognito Hosted UI Autentication in Django?


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(

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 so that I can continue the login. I tried variations of request.GET that did not work.

Any help is appreciated!!


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.

Answered By – bourgeoisna

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published