本文整理汇总了Python中allauth.socialaccount.models.SocialToken.app方法的典型用法代码示例。如果您正苦于以下问题:Python SocialToken.app方法的具体用法?Python SocialToken.app怎么用?Python SocialToken.app使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类allauth.socialaccount.models.SocialToken
的用法示例。
在下文中一共展示了SocialToken.app方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dispatch
# 需要导入模块: from allauth.socialaccount.models import SocialToken [as 别名]
# 或者: from allauth.socialaccount.models.SocialToken import app [as 别名]
def dispatch(self, request):
if 'error' in request.GET or not 'code' in request.GET:
# TODO: Distinguish cancel from error
return render_authentication_error(request)
app = self.adapter.get_provider().get_app(self.request)
client = self.get_client(request, app)
try:
r = praw.Reddit('OAuth Sketchdaily Schedule by u/davidwinters ver 0.1.')
r.set_oauth_app_info(client.consumer_key, client.consumer_secret, 'http://themes.sketchdaily.net/accounts/redditprovider/login/callback/')
access_token = r.get_access_information(request.GET['code'])
user = r.get_me()
extra = r.get_my_moderation()
# access_token = client.get_access_token(request.GET['code'])
token = SocialToken(token=access_token)
#token = self.adapter.parse_token(access_token)
token.app = app
login = self.adapter.complete_login(request,
app,
token,
response=access_token, user=user, extra=extra)
token.account = login.account
login.token = token
login.state = SocialLogin.unmarshall_state(request.REQUEST
.get('uniqueKey'))
return complete_social_login(request, login)
except OAuth2Error:
return render_authentication_error(request)
示例2: validate
# 需要导入模块: from allauth.socialaccount.models import SocialToken [as 别名]
# 或者: from allauth.socialaccount.models.SocialToken import app [as 别名]
def validate(self, attrs):
view = self.context.get('view')
request = self._get_request()
if not view:
raise serializers.ValidationError(
'View is not defined, pass it as a context variable'
)
adapter_class = getattr(view, 'adapter_class', None)
if not adapter_class:
raise serializers.ValidationError('Define adapter_class in view')
adapter = adapter_class()
app = adapter.get_provider().get_app(request)
if('access_token' in attrs) and ('token_secret' in attrs):
access_token = attrs.get('access_token')
token_secret = attrs.get('token_secret')
else:
raise serializers.ValidationError('Incorrect input. access_token and token_secret are required.')
request.session['oauth_api.twitter.com_access_token'] = {
'oauth_token': access_token,
'oauth_token_secret': token_secret,
}
token = SocialToken(token=access_token, token_secret=token_secret)
token.app = app
try:
login = self.get_social_login(adapter, app, token, access_token)
complete_social_login(request, login)
except HTTPError:
raise serializers.ValidationError('Incorrect value')
if not login.is_existing:
login.lookup()
login.save(request, connect=True)
attrs['user'] = login.account.user
return attrs