• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python client.Client类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: handle_stackexchange

 def handle_stackexchange(self, data):
     self.send_response(302)
     c = Client(auth_endpoint="https://stackexchange.com/oauth",
         client_id=config["stackexchange.client_id"],
         redirect_uri="http://localhost/login/stackexchange")
     self.send_header("Location", c.auth_uri())
     self.end_headers()
开发者ID:Raekkeri,项目名称:sanction,代码行数:7,代码来源:server.py


示例2: test_inst

    def test_inst(self):
        from urlparse import urlparse
        from urlparse import parse_qsl
        from sanction.client import Client

        c = get_config()
        client = Client(TestAdapterImpl, c)
        uri = client.flow.authorization_uri()
        o = urlparse(uri)
        qs = dict(parse_qsl(o.query))

        self.assertEquals(qs["scope"], c["testadapterimpl.scope"])
        self.assertEquals(qs["redirect_uri"],
            c["testadapterimpl.redirect_uri"])
        self.assertEquals(qs["response_type"], "code")
        self.assertEquals(qs["client_id"], c["testadapterimpl.client_id"])
        
        start_server()
        cred = client.flow.authorization_received({
            "code": "test"
        })
        self.assertTrue(isinstance(cred, BearerCredentials))

        start_server()
        r = client.request("/me")
开发者ID:nirleka,项目名称:py-sanction,代码行数:25,代码来源:test_client.py


示例3: handle_instagram

	def handle_instagram(self, data):
		self.send_response(302)
		c = Client(auth_endpoint="https://api.instagram.com/oauth/authorize/",
				client_id=config["instagram.client_id"],
				redirect_uri="http://localhost:8080/login/instagram")
		self.send_header("Location", c.auth_uri())
		self.end_headers()
开发者ID:AlecTaylor,项目名称:sanction,代码行数:7,代码来源:server.py


示例4: handle_foursquare_login

	def handle_foursquare_login(self, data):
		self.send_response(200)
		self.send_header("Content-type", "text/html")
		self.log_message(self.path)
		self.end_headers()

		c = Client(
			token_endpoint="https://foursquare.com/oauth2/access_token",
			resource_endpoint="https://api.foursquare.com/v2",
			redirect_uri="http://localhost:8080/login/foursquare",
			client_id=config["foursquare.client_id"],
			client_secret=config["foursquare.client_secret"],
			)
		c.access_token_key = "oauth_token"
		c.request_token(data=data)

		d = c.request("/users/24700343")

		self.wfile.write("Access token: %s<br>" % c.access_token)
		self.wfile.write("First name: %s<br>" % 
			d["response"]["user"]["firstName"])
		self.wfile.write("Last name: %s<br>" % 
			d["response"]["user"]["lastName"])
		self.wfile.write("Email: %s<br>" % 
			d["response"]["user"]["contact"]["email"])
开发者ID:AlecTaylor,项目名称:sanction,代码行数:25,代码来源:server.py


示例5: handle_bitly

	def handle_bitly(self, data):
		self.send_response(302)
		c = Client(auth_endpoint="https://bitly.com/oauth/authorize",
				client_id=config["bitly.client_id"],
				redirect_uri="http://localhost:8080/login/bitly")
		self.send_header("Location", c.auth_uri())
		self.end_headers()
开发者ID:AlecTaylor,项目名称:sanction,代码行数:7,代码来源:server.py


示例6: handle_foursquare

	def handle_foursquare(self, data):
		self.send_response(302)
		c = Client(auth_endpoint="https://foursquare.com/oauth2/authenticate",
				client_id=config["foursquare.client_id"],
				redirect_uri="http://localhost:8080/login/foursquare")
		self.send_header("Location", c.auth_uri())
		self.end_headers()
开发者ID:AlecTaylor,项目名称:sanction,代码行数:7,代码来源:server.py


示例7: handle_facebook_login

	def handle_facebook_login(self, data):
		self.send_response(200)
		self.send_header("Content-type", "text/html")
		self.log_message(self.path)
		self.end_headers()

		c = Client(
			token_endpoint="https://graph.facebook.com/oauth/access_token",
			resource_endpoint="https://graph.facebook.com",
			redirect_uri="http://localhost:8080/login/facebook",
			client_id=config["facebook.client_id"],
			client_secret=config["facebook.client_secret"])
		c.request_token(data=data, 
			parser = lambda data: dict(parse_qsl(data)))

		d = c.request("/me")

		self.wfile.write("Access token: %s<br>" % c.access_token)
		self.wfile.write("First name: %s<br>" % d["first_name"])
		self.wfile.write("Last name: %s<br>" % d["last_name"])
		self.wfile.write("Email: %s<br>" % d["email"])

		# to see a wall post in action, uncomment this
		try:
			d = c.request("/me/feed", data=urlencode({
				"message": "test post from py-sanction"
			}))
			self.wfile.write(
				"I posted a message to your wall (in sandbox mode, nobody else will see it)")
		except:
			self.wfile.write(
				"Unable to post to your wall")
开发者ID:AlecTaylor,项目名称:sanction,代码行数:32,代码来源:server.py


示例8: handle_foursquare_login

    def handle_foursquare_login(self, data):
        def token_transport(url, access_token, data=None, method=None):
            parts = urlsplit(url)
            query = dict(parse_qsl(parts.query))
            query.update({
                'oauth_token': access_token
            })
            url = urlunsplit((parts.scheme, parts.netloc, parts.path,
                urlencode(query), parts.fragment))
            try:
                req = Request(url, data=data, method=method)
            except TypeError:
                req = Request(url, data=data)
                req.get_method = lambda: method
            return req

        c = Client(
            token_endpoint='https://foursquare.com/oauth2/access_token',
            resource_endpoint='https://api.foursquare.com/v2',
            redirect_uri='http://localhost/login/foursquare',
            client_id=config['foursquare.client_id'],
            client_secret=config['foursquare.client_secret'],
            token_transport=token_transport
            )
        c.request_token(code=data['code'])

        self.dump_client(c)
        d = c.request('/users/24700343')
        self.dump_response(d)
开发者ID:brianru,项目名称:sanction,代码行数:29,代码来源:server.py


示例9: handle_foursquare

 def handle_foursquare(self, data):
     self.send_response(302)
     c = Client(auth_endpoint='https://foursquare.com/oauth2/authenticate',
             client_id=config['foursquare.client_id'],
             redirect_uri='http://localhost/login/foursquare')
     self.send_header('Location', c.auth_uri())
     self.end_headers()
开发者ID:kobeBigs,项目名称:sanction,代码行数:7,代码来源:server.py


示例10: authenticate

    def authenticate(self, code=None, provider_key=None):
        """ Django API function, authenticating a user

        Authentication method required of a Django authentication backend. If
        successful, this method will retrieve an access token from the
        provider.

        :note: A method ``fetch_user`` is expected as a static function on the
               custom user class. This is responsible for retrieiving the
               actual user instance required by the Django backend. It will
               receive the ``provider_key`` and an instance of a sanction
               client (which should contain the access token)

        :param code: The code returned by the OAuth 2.0 provider once the user
                     has given your application authorization.
        :param provider_key: The key for the provider sending authorization
                             data. This should match the keys used in your
                             settings file for ``SANCTION_PROVIDERS``.
        """
        model = get_user_model()
        provider = settings.SANCTION_PROVIDERS[provider_key]
        
        c = SanctionClient(token_endpoint=provider['token_endpoint'],
            resource_endpoint=provider['resource_endpoint'],
            auth_endpoint=provider['auth_endpoint'],
            client_id=provider['client_id'],
            client_secret=provider['client_secret'],
            redirect_uri=provider['redirect_uri'])

        c.request_token(code=code, parser=provider.get('parser', None))

        return model.fetch_user(provider_key, c)
开发者ID:johnjwatson,项目名称:django-sanction,代码行数:32,代码来源:backends.py


示例11: handle_stackexchange_login

    def handle_stackexchange_login(self, data):
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.log_message(self.path)
        self.end_headers()

        c = Client(StackExchange, get_config())
        cred = c.flow.authorization_received(data)

        d = c.request("/me", body=urlencode({
            "site": "stackoverflow"
        }))

        self.wfile.write("<!DOCTYPE html>")
        self.wfile.write("<head><meta charset=\"utf-8\"/></head><body>")
        self.wfile.write("Access token: %s<br>" % cred.access_token)
        self.wfile.write("Type: %s<br>" % cred.token_type)
        self.wfile.write("Expires in: %d<br>" % cred.expires_in)

        # stackexchange gzips all data
        h = StringIO(d)
        gzip_data = GzipFile(fileobj=h)
        d = gzip_data.read()
        gzip_data.close()
        self.wfile.write(d)
        self.wfile.write("</body></html>")
开发者ID:nirleka,项目名称:py-sanction,代码行数:26,代码来源:server.py


示例12: handle_facebook_login

    def handle_facebook_login(self, data):
        c = Client(
            token_endpoint='https://graph.facebook.com/oauth/access_token',
            resource_endpoint='https://graph.facebook.com',
            redirect_uri='http://localhost/login/facebook',
            client_id=config['facebook.client_id'],
            client_secret=config['facebook.client_secret'])

        c.request_token(code=data['code'],
            parser=lambda data: dict(parse_qsl(data)))

        self.dump_client(c)
        d = c.request('/me')
        self.dump_response(d)

        try:
            d = c.request('/me/feed', data=urlencode({
                'message': 'test post from py-sanction'
            }))
            self.wfile.write(
                'I posted a message to your wall (in sandbox mode, nobody '
                'else will see it)'.encode(ENCODING_UTF8))
        except:
            self.wfile.write(
                'Unable to post to your wall')
开发者ID:kobeBigs,项目名称:sanction,代码行数:25,代码来源:server.py


示例13: process_request

    def process_request(self, request):
        if not request.user.is_anonymous():
            try:
                provider = filter(lambda p: p["name"] == request.user.provider_key,
                    (settings.OAUTH2_PROVIDERS[k] for k in
                        settings.OAUTH2_PROVIDERS))[-1]

                c = Client(token_endpoint=provider["token_endpoint"],
                    resource_endpoint=provider["resource_endpoint"],
                    auth_endpoint=provider["auth_endpoint"],
                    redirect_uri=provider.get("redirect_uri", None),
                    client_id=provider["client_id"],
                    client_secret=provider["client_secret"])
                
                c.access_token = request.user.access_token
                c.expires = request.user.expires

                setattr(request.user, "resource", c)

            # play nice with other authentication backends
            except IndexError:
                raise KeyError("Provider %s doesn't exist" % 
                    request.user.provider_key)
            except AttributeError: 
                # current user isn't a django_sanction user
                pass
开发者ID:mramu111,项目名称:django-sanction,代码行数:26,代码来源:middleware.py


示例14: handle_instagram

 def handle_instagram(self, data):
     self.send_response(302)
     c = Client(auth_endpoint='https://api.instagram.com/oauth/authorize/',
             client_id=config['instagram.client_id'],
             redirect_uri='http://localhost/login/instagram')
     self.send_header('Location', c.auth_uri())
     self.end_headers()
开发者ID:kobeBigs,项目名称:sanction,代码行数:7,代码来源:server.py


示例15: handle_github

 def handle_github(self, data):
     self.send_response(302)
     c = Client(auth_endpoint="https://github.com/login/oauth/authorize",
             client_id=config["github.client_id"],
             redirect_uri="http://localhost/login/github")
     self.send_header("Location", c.auth_uri())
     self.end_headers()
开发者ID:Raekkeri,项目名称:sanction,代码行数:7,代码来源:server.py


示例16: handle_google

 def handle_google(self, data):
     self.send_response(302)
     c = Client(auth_endpoint='https://accounts.google.com/o/oauth2/auth',
         client_id=config['google.client_id'],
         redirect_uri='http://localhost/login/google')
     self.send_header('Location', c.auth_uri(
         scope=config['google.scope'].split(','), access_type='offline'))    
     self.end_headers()
开发者ID:kobeBigs,项目名称:sanction,代码行数:8,代码来源:server.py


示例17: test_request_token

    def test_request_token(self):
        c = Client(token_endpoint=token_endpoint)

        try:
            c.request_token()
            self.fail()
        except:
            pass
开发者ID:brianru,项目名称:sanction,代码行数:8,代码来源:tests.py


示例18: handle_deviantart

 def handle_deviantart(self, data):
     self.send_response(302)
     c = Client(
         auth_endpoint='https://www.deviantart.com/oauth2/draft15/authorize',
         client_id=config['deviantart.client_id'],
         redirect_uri=config['deviantart.redirect_uri'])
     self.send_header('Location', c.auth_uri())
     self.end_headers()
开发者ID:kobeBigs,项目名称:sanction,代码行数:8,代码来源:server.py


示例19: handle_facebook

 def handle_facebook(self, data):
     self.send_response(302)
     c = Client(auth_endpoint="https://www.facebook.com/dialog/oauth",
             client_id=config["facebook.client_id"],
             redirect_uri="http://localhost/login/facebook")
     self.send_header("Location", c.auth_uri(
         scope=config["facebook.scope"].split(","),
         scope_delim=","))
     self.end_headers()
开发者ID:Raekkeri,项目名称:sanction,代码行数:9,代码来源:server.py


示例20: callback

def callback():
    client = Client(token_endpoint='https://api.sandbox.slcedu.org/api/oauth/token',
        resource_endpoint='https://api.sandbox.slcedu.org/api/rest/v1',
        client_id=client_id, client_secret=shared_secret,
        redirect_uri='http://slcgoals.cloudapp.net/callback')
    client.request_token(code=request.args['code'])
    access_token = client.access_token
    login_user(load_user(access_token))
    return redirect('/')
开发者ID:fugu13,项目名称:dreamon,代码行数:9,代码来源:dreamon.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sandbox.Sandbox类代码示例发布时间:2022-05-27
下一篇:
Python utest.raises函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap