-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
[Question] How to use the convert token logic inside Django? #212
Comments
I could not understand your question. Be clearer, more concise and give examples. |
I'm trying to convert the token from the Google OAuth callback, getting the token from the Django session and returning it to another application. But when I deploy the server, it's not being able to request to itself. Then I'm asking if it's possible to call this lib view internally or something like that def complete_google(request: HttpRequest) -> Response:
social: str = "google-oauth2"
code: str = request.GET.get("code")
url: str = "https://oauth2.googleapis.com/token"
payload: Dict[str, str] = {
"client_id": SOCIAL_AUTH_GOOGLE_OAUTH2_KEY,
"client_secret": SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET,
"code": code,
"redirect_uri": f"{DJANGO_BASE_URL}/complete/google-oauth2/",
"grant_type": "authorization_code",
}
headers: Dict[str, str] = {"Content-Type": "application/x-www-form-urlencoded"}
response: Response = requests.post(url, headers=headers, data=payload)
response_json: Dict[str, str] = response.json()
google_auth_token = response_json.get("access_token")
url: str = f"{DJANGO_BASE_URL}/auth/convert-token/"
payload: Dict[str, str] = {
"grant_type": "convert_token",
"backend": social,
"client_id": APPLICATION_CLIENT_ID_GOOGLE,
"client_secret": APPLICATION_CLIENT_SECRET_GOOGLE,
"token": google_auth_token,
}
headers: Dict[str, str] = {"Content-Type": "application/x-www-form-urlencoded"}
response: Response = requests.post(url, headers=headers, data=payload)
return Response(
response.json(),
) |
What is your django base url? You could do it with self.request.build_absolute_uri('/')[:-1] Or something like that. Finishing the day here. Hope you find it out! |
That's only the URL that Django application it's running. For example, if it's running locally with NGINX is Thanks for the info. I will try out. Good day! |
Succeeded? |
No, I'm moving this to a different application, that's going to be in charge of validating the users. So I guess I will not encounter this problem. But if is there a way to make it to call itself would be ideal. Is there any way to call the |
Edit: Removing due to update in #203 (comment) |
Careful, you should never return the client secret like that. It should not be exposed for security reasons. |
I want to convert the token from OAuth to the Django session one, but I need to do it inside Django. How can this be achieved?
Tried to use
requests
and making a POST call internally but it's not working.The text was updated successfully, but these errors were encountered: