当前位置: 首页>>代码示例>>Python>>正文


Python models.SocialToken类代码示例

本文整理汇总了Python中allauth.socialaccount.models.SocialToken的典型用法代码示例。如果您正苦于以下问题:Python SocialToken类的具体用法?Python SocialToken怎么用?Python SocialToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SocialToken类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dispatch

 def dispatch(self, request):
     """
     View to handle final steps of OAuth based authentication where the user
     gets redirected back to from the service provider
     """
     login_done_url = reverse(self.adapter.provider_id + "_callback")
     client = self._get_client(request, login_done_url)
     if not client.is_valid():
         if 'denied' in request.GET:
             return HttpResponseRedirect(reverse('socialaccount_login_cancelled'))
         extra_context = dict(oauth_client=client)
         return render_authentication_error(request, extra_context)
     app = self.adapter.get_provider().get_app(request)
     try:
         access_token = client.get_access_token()
         token = SocialToken(app=app,
                             token=access_token['oauth_token'],
                             token_secret=access_token['oauth_token_secret'])
         login = self.adapter.complete_login(request, app, token)
         token.account = login.account
         login.token = token
         login.state = SocialLogin.unmarshall_state \
             (request.session.pop('oauth_login_state', None))
         return complete_social_login(request, login)
     except OAuthError:
         return render_authentication_error(request)
开发者ID:GVRV,项目名称:django-allauth,代码行数:26,代码来源:views.py

示例2: dispatch

 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)
开发者ID:MacAnthony,项目名称:postschedule,代码行数:27,代码来源:views.py

示例3: parse_token

 def parse_token(self, data):
     token = SocialToken(token=data["access_token"])
     token.token_secret = data.get("refresh_token", "")
     expires_in = data.get(self.expires_in_key, None)
     if expires_in:
         token.expires_at = timezone.now() + timedelta(seconds=int(expires_in))
     return token
开发者ID:pennersr,项目名称:django-allauth,代码行数:7,代码来源:views.py

示例4: dispatch

 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:
         access_token = client.get_access_token(request.GET['code'])
         token = SocialToken(app=app,
                             token=access_token)
         login = self.adapter.complete_login(request,
                                             app,
                                             token)
         token.account = login.account
         login.token = token
         return complete_social_login(request, login)
     except OAuth2Error:
         return render_authentication_error(request)
开发者ID:opkorz,项目名称:friendbook,代码行数:18,代码来源:views.py

示例5: dispatch

 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:
         access_token, refresh_token = client.get_access_token(request.GET['code'])
         token = SocialToken(app=app,
                             token=access_token,
                             token_secret=refresh_token)
         login = self.adapter.complete_login(request, app, token)
         token.account = login.account
         login.token = token
         login.state = SocialLogin.unmarshall_state(request.REQUEST
                                                    .get('state'))
         login.redirect_account_url = request.session.pop('redirect_account_url', None)
         return complete_social_login(request, login)
     except OAuth2Error:
         return render_authentication_error(request)
开发者ID:artminster,项目名称:django-allauth,代码行数:20,代码来源:views.py

示例6: validate

    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
开发者ID:Heldroe,项目名称:django-rest-auth,代码行数:41,代码来源:social_serializers.py

示例7: complete_login

    def complete_login(self, request, app, token, email_addresses=[]):

        client = TwitterAPI(request, app.client_id, app.secret,
                            self.request_token_url)
        extra_data = client.get_user_info()
        uid = extra_data['id']

        user = User.objects.filter(username=extra_data.get('screen_name'))

        if user:
            return user
        else:

            user = get_adapter() \
                .populate_new_user(username=extra_data.get('screen_name'),
                                   name=extra_data.get('name'))
            user.save()
            account = SocialAccount(user=user,
                                    uid=uid,
                                    provider=TwitterProvider.id,
                                    extra_data=extra_data)
            account.save()
            application = SocialApp.objects.get(secret=app.secret)
            sample_token = SocialToken.objects.filter(app=application, account=account)
            if sample_token:
                token = sample_token[0]
            else:
                token = SocialToken(app=application,
                                    account=account,
                                    token=request.session["oauth_api.twitter.com_access_token"]["oauth_token"],
                                    token_secret=request.session["oauth_api.twitter.com_access_token"][
                                        "oauth_token_secret"])
                token.save()

            mail = send_email_confirmation(request=request, user=user, signup=True)
            return SocialLogin(account=account, token=token, email_addresses=email_addresses)
开发者ID:OPENi-ict,项目名称:api-framework,代码行数:36,代码来源:SignIn.py

示例8: test_get_redir_user_demo

 def test_get_redir_user_demo(self):
     payload = {"user": {"username": self.demo["username"]}}
     self.client.login(username=payload["user"]["username"], password="password")
     sapp = SocialApp(provider='github', name='Github', client_id='<test>', secret='<test>')
     sapp.save()
     sacc = SocialAccount(uid=1001, user=self.test_user, provider="github")
     sacc.save()
     stoken = SocialToken(app=sapp, account=sacc, token="test_token")
     stoken.save()
     response = self.client.post('/accounts/profile', follow=True)
     first_url, first_response = response.redirect_chain[0]
     self.assertEqual(first_url, "/login?status=passed&token=test_token&username=testname&user_id=1001")
     self.client.login(username=payload["user"]["username"], password="password")
     stoken = SocialToken(app=sapp, account=sacc, token="test_token")
     stoken.save()
     response = self.client.post('/accounts/profile', follow=True)
     first_url, first_response = response.redirect_chain[0]
     self.assertEqual(first_url, "/login?status=passed&token=test_token&username=testname&user_id=1001")
开发者ID:Cloud-CV,项目名称:cvfy-frontend,代码行数:18,代码来源:tests.py


注:本文中的allauth.socialaccount.models.SocialToken类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。