django-rest-auth
django-rest-auth copied to clipboard
Allow dynamic callback_url and client_class class attributes
Callback urls require being absolute, which is pretty cumbersome espacially when dealing with differents environments (dev/staging/production for instance). Being able to provide dynamic callbacks url hence allows for things like this:
class GitHubLogin(SocialLoginView):
adapter_class = github_views.GitHubOAuth2Adapter
client_class = OAuth2Client
# use the same callback url as defined in your GitHub app, this url must be
# absolute
def get_callback_url(self):
return self.request.build_absolute_uri(reverse('github_callback'))
urlpatterns = [
...,
path('auth/github/', GitHubLogin.as_view()),
path('auth/github/callback/', github_callback, name='github_callback')
]
Which really comes in handy in multiple environments.
I also changed client_class the same way for code homegeneity concerns (even though I did not have to use it in my own projects).
The "basic way" of declaring these will of course still work:
class GitHubLogin(SocialLoginView):
adapter_class = github_views.GitHubOAuth2Adapter
client_class = OAuth2Client
callback_url = 'http://localhost:8000/auth/github/callback/'
Coverage decreased (-0.2%) to 96.186% when pulling d7532b875ed77f9fda94863aa400b3d6d926a64a on michaeldel:master into 95fafe5e0f6716296a1c664c2b870876a6b4e0cc on Tivix:master.
Hi, as a user of rest-auth, thanks for the contribution! This repo is not maintained anymore, so the development moved to dj-rest-auth. (reference: https://github.com/Tivix/django-rest-auth/issues/568) It may be best, if you move this PR there. (and upgrade to using dj_rest_auth)
new repo link: https://github.com/jazzband/dj-rest-auth (I'm not the upkeeper of that repo, it just makes sense for me to help you merge your PR)
Many Thanks, Barney
@BarnabasSzabolcs thank you for suggesting it, I was not aware of this fork. PR has been submitted on this new fork here: https://github.com/jazzband/dj-rest-auth/pull/80
Thanks Michael!