def get_redirect_url(self, *args, **kwargs):
client = OAuth2Session(
client_id=settings.OAUTH['client_id'],
redirect_uri=settings.OAUTH['redirect_domain'] + reverse('oauth_return_view'),
scope=['view_profile'],
)
# extract next url
next_url = self.request.GET.get('next', None)
# save it to the session
if next_url and is_safe_url(next_url):
self.request.session['login_next_url'] = next_url
# the user is then redirected to the auth provider with the right parameters
url, state = client.authorization_url(settings.OAUTH['authorization_url'])
# the nonce is saved inside the session
self.request.session['oauth2_nonce'] = state
return url
评论列表
文章目录