Skip to content
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

Allow dynamic callback_url and client_class class attributes #448

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

michaeldel
Copy link

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/'

@coveralls
Copy link

coveralls commented Jul 26, 2018

Coverage Status

Coverage decreased (-0.2%) to 96.186% when pulling d7532b8 on michaeldel:master into 95fafe5 on Tivix:master.

@BarnabasSzabolcs
Copy link

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: #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

@michaeldel
Copy link
Author

@BarnabasSzabolcs thank you for suggesting it, I was not aware of this fork. PR has been submitted on this new fork here: iMerica/dj-rest-auth#80

@BarnabasSzabolcs
Copy link

Thanks Michael!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants