Tôi đang sử dụng tuyệt vời Python social auth với Django
.
Tuy nhiên, tại thời điểm này, mọi quá trình được gọi, người dùng mới được tạo. Tôi chỉ cần mã thông báo (access_token
và refresh_token
) từ quy trình. Làm thế nào điều này có thể đạt được? Thông qua một số loại đường ống?Sử dụng xác thực xã hội Python để chỉ nhận mã thông báo
Đây là pipeline.py
mã của tôi tại thời điểm (viết tắt):
def get_token(backend, user, response, *args, **kwargs):
# get token from the oauth2 flow
social = user.social_auth.get(provider='google-oauth2')
access_token = social.extra_data['access_token']
refresh_token = social.extra_data.get('refresh_token')
Và settings.py
tập tin tương ứng:
# set django session
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
# psa settings
SOCIAL_AUTH_URL_NAMESPACE = 'social'
# see http://psa.matiasaguirre.net/docs/configuration/settings.html
SOCIAL_AUTH_UUID_LENGTH = 32
AUTHENTICATION_BACKENDS = (
#'social.backends.facebook.FacebookOAuth2',
'social.backends.google.GoogleOAuth2',
#'social.backends.twitter.TwitterOAuth',
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
'youtube.pipeline.get_token',
)
* "... mọi khi quá trình được gọi, người dùng mới được tạo ..." * - quy trình nào? – xyres
@xyres: Quá trình xác thực người dùng đối với Google+ hoặc Facebook hoặc Twitter. Nó được bắt đầu với một liên kết trong mẫu. – Jan