简体   繁体   中英

Lost with django-social-auth and custom oauth2 backen

This may not be a very good stackoverflow question because I am so lost I think my question will appear like I have made no effort.

I want to get the user's email from Xero, a cloud accounting app which specifically allows for this ( https://developer.xero.com/documentation/oauth2/sign-in )

When I create a Xero "app" to get the necessary credentials, I need to provide an OAuth 2.0 redirect URI, and I think this is very common or even universal for oauth2 authentication. I can't see an example of how I provide this URL to the configuration of my backend (a subclass of BaseOAuth2). Apart from being a redirect URL, it must also be provided in the AUTHORIZATION_URL.

The Xero URL template is https://login.xero.com/identity/connect/authorize?response_type=code&client_id=YOURCLIENTID&redirect_uri=YOURREDIRECTURI&scope=email&state=1234

I have read quite a few tutorials. I can't find any on adding a custom oauth2 backend, but in this tutorial there are examples for GitHub and Twitter:

https://simpleisbetterthancomplex.com/tutorial/2016/10/24/how-to-add-social-login-to-django.html

In both cases, the tutorial says to provide a callback URL of the form http://localhost:8000/oauth/complete/twitter/ when defining the app on the authenticator's side.

Is this a hard-coded, undocumented default? Or do I need to define it somewhere in my configuration? In the tutorial, I can't see any reference to a callback url in the backend code for github.py or twitter.py.

So I am lost because I don't know my Django app handles the redirect from Xero if I don't tell it what the redirecting URL will be, and I don't know how a custom backend can elegantly create a valid auth URL because it needs to have a redirect URL provided. I can't find documentation on this that I can understand, and I can't work it out from the source code.

Tutorial explains how to use OAuth providers already available in the python-social-auth plugin. Check the provided page for the list of available integrations.

What you really need here is to add your custom provider plugin for the Xero service. You can use this manual for adding a new backend.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM