%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib64/python2.7/site-packages/tornado/
Upload File :
Create Path :
Current File : //lib64/python2.7/site-packages/tornado/auth.pyc

�
��L]c@�svdZddlmZmZmZmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZmZmZyddlZWn ek
r@ddl j!ZnXyddl j!Z"Wnek
rsddl#Z"nXye$Wne%k
r�e&Z$nXde'fd
��YZ(d�Z)d�Z*de+fd��YZ,de+fd��YZ-de+fd��YZ.de-fd��YZ/de.fd��YZ0de.fd��YZ1idd�Z3idd�Z4d�Z5d�Z6dS( sKThis module contains implementations of various third-party
authentication schemes.

All the classes in this file are class mixins designed to be used with
the `tornado.web.RequestHandler` class.  They are used in two ways:

* On a login handler, use methods such as ``authenticate_redirect()``,
  ``authorize_redirect()``, and ``get_authenticated_user()`` to
  establish the user's identity and store authentication tokens to your
  database and/or cookies.
* In non-login handlers, use methods such as ``facebook_request()``
  or ``twitter_request()`` to use the authentication tokens to make
  requests to the respective services.

They all take slightly different arguments due to the fact all these
services implement authentication and authorization slightly differently.
See the individual service classes below for complete documentation.

Example usage for Google OAuth:

.. testcode::

    class GoogleOAuth2LoginHandler(tornado.web.RequestHandler,
                                   tornado.auth.GoogleOAuth2Mixin):
        @tornado.gen.coroutine
        def get(self):
            if self.get_argument('code', False):
                user = yield self.get_authenticated_user(
                    redirect_uri='http://your.site.com/auth/google',
                    code=self.get_argument('code'))
                # Save the user with e.g. set_secure_cookie
            else:
                yield self.authorize_redirect(
                    redirect_uri='http://your.site.com/auth/google',
                    client_id=self.settings['google_oauth']['key'],
                    scope=['profile', 'email'],
                    response_type='code',
                    extra_params={'approval_prompt': 'auto'})

.. testoutput::
   :hide:


.. versionchanged:: 4.0
   All of the callback interfaces in this module are now guaranteed
   to run their callback with an argument of ``None`` on error.
   Previously some functions would do this while others would simply
   terminate the request on their own.  This change also ensures that
   errors are more consistently reported through the ``Future`` interfaces.
i(tabsolute_importtdivisiontprint_functiontwith_statementN(tTracebackFuturet
return_future(tgen(t
httpclient(tescape(t
url_concat(tgen_log(tExceptionStackContext(tutunicode_typetArgReplacert	AuthErrorcB�seZRS((t__name__t
__module__(((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyRfscC�sMy|j�}Wn,tk
r>}tjt|��d}nX||�dS(N(tresultRR
twarningtstrtNone(tcallbacktfutureRte((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyt_auth_future_to_callbackjs
c�s4t�d��tj����fd��}|S(s�Similar to tornado.concurrent.return_future, but uses the auth
    module's legacy callback interface.

    Note that when using this decorator the ``callback`` parameter
    inside the function will actually be a future.
    Rc�s�t���j�||�\}}}|dk	rO�jtjt|��n�fd�}t|���||�WdQX�S(Nc�s.�j�rtS�j|||f�tSdS(N(tdonetFalsetset_exc_infotTrue(ttyptvaluettb(R(s2/usr/lib64/python2.7/site-packages/tornado/auth.pythandle_exception�s(RtreplaceRtadd_done_callbackt	functoolstpartialRR(targstkwargsRR!(tftreplacer(Rs2/usr/lib64/python2.7/site-packages/tornado/auth.pytwrapper|s	
(RR$twraps(R(R*((R(R)s2/usr/lib64/python2.7/site-packages/tornado/auth.pyt_auth_return_futuress!tOpenIdMixincB�seeZdZed
ddddgd
d��Zed
d��Zgd
d�Zd�Z	d	�Z
RS(s�Abstract implementation of OpenID and Attribute Exchange.

    Class attributes:

    * ``_OPENID_ENDPOINT``: the identity provider's URI.
    tnametemailtlanguagetusernamecC�sS|p|jj}|j|d|�}|j|jdtj|��|�dS(s�Redirects to the authentication URL for this service.

        After authentication, the service will redirect back to the given
        callback URI with additional parameters including ``openid.mode``.

        We request the given attributes for the authenticated user by
        default (name, email, language, and username). If you don't need
        all those attributes for your app, you can request fewer with
        the ax_attrs keyword argument.

        .. versionchanged:: 3.1
           Returns a `.Future` and takes an optional callback.  These are
           not strictly necessary as this method is synchronous,
           but they are supplied for consistency with
           `OAuthMixin.authorize_redirect`.
        tax_attrst?N(trequestturit_openid_argstredirectt_OPENID_ENDPOINTturllib_parset	urlencode(tselftcallback_uriR2RR&((s2/usr/lib64/python2.7/site-packages/tornado/auth.pytauthenticate_redirect�s!cC�s�td�|jjj�D��}td�|d<|j}|dkrV|j�}n|j|t	j
|j|�dddtj
|��dS(s�Fetches the authenticated user data upon redirect.

        This method should be called by the handler that receives the
        redirect from the `authenticate_redirect()` method (which is
        often the same as the one that calls it; in that case you would
        call `get_authenticated_user` if the ``openid.mode`` parameter
        is present and `authenticate_redirect` if it is not).

        The result of this method will generally be used to set a cookie.
        cs�s%|]\}}||dfVqdS(i����N((t.0tktv((s2/usr/lib64/python2.7/site-packages/tornado/auth.pys	<genexpr>�stcheck_authenticationsopenid.modetmethodtPOSTtbodyN(tdictR4t	argumentstitemsRR8Rtget_auth_http_clienttfetchR$R%t_on_authentication_verifiedR9R:(R;Rthttp_clientR&turl((s2/usr/lib64/python2.7/site-packages/tornado/auth.pytget_authenticated_user�s
"	c	C�s�tj|jj�|�}idd6dd6dd6|d6tj|d�d6d	d
6}|rK|jidd6d
d6�t|�}g}d|kr�|tddddg�8}|dddg7}|jidd6dd6dd6�nidd6dd6dd6}x-|D]%}|||d|<|j|�qWd j|�|d!<n|r�|jid"d#6|jjj	d$�d%d&6|d'6�n|S((Ns http://specs.openid.net/auth/2.0s	openid.nss2http://specs.openid.net/auth/2.0/identifier_selectsopenid.claimed_idsopenid.identitysopenid.return_tot/sopenid.realmt
checkid_setupsopenid.modeshttp://openid.net/srv/ax/1.0sopenid.ns.axt
fetch_requestsopenid.ax.modeR.t	firstnametfullnametlastnames$http://axschema.org/namePerson/firstsopenid.ax.type.firstnameshttp://axschema.org/namePersonsopenid.ax.type.fullnames#http://axschema.org/namePerson/lastsopenid.ax.type.lastnames!http://axschema.org/contact/emailR/s!http://axschema.org/pref/languageR0s'http://axschema.org/namePerson/friendlyR1sopenid.ax.type.t,sopenid.ax.requireds,http://specs.openid.net/extensions/oauth/1.0sopenid.ns.oautht:isopenid.oauth.consumersopenid.oauth.scope(
turlparseturljoinR4tfull_urltupdatetsettappendtjointhosttsplit(	R;R<R2toauth_scopeRLR&trequiredtknown_attrsR.((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR6�sF
		

	c
�s|jsd|jkr?|jtd|jp3|j��dSd�xL�jjD]>}|jd�rR�j|�t	d�krR|d�PqRqRW��fd�}|d�}|d�}|d	�}|d
�}|d�}|d�j
�}	t�}
g}|r#||
d
<|j|�n|rC||
d<|j|�n|rV||
d<nB|rxt	d�j
|�|
d<n |r�|jd�d|
d<n|r�||
d<n|	r�|	|
d<n|r�||
d<n�jdd�}|r�||
d<n|j|
�dS(Ns
is_valid:truesInvalid OpenID response: %ss
openid.ns.shttp://openid.net/srv/ax/1.0i
c�s��std�Sd�d}d}xd�jjj�D]P}�j|�|kr7|j|�r7|t|�}d�d|}Pq7q7W|s�td�S�j|td��S(Ntsopenid.s.type.s.value.(RRR4RFtkeystget_argumentt
startswithtlen(R5tprefixtax_nameR.tpart(tax_nsR;(s2/usr/lib64/python2.7/site-packages/tornado/auth.pyt
get_ax_args
$
s!http://axschema.org/contact/emailshttp://axschema.org/namePersons$http://axschema.org/namePerson/firsts#http://axschema.org/namePerson/lasts'http://axschema.org/namePerson/friendlys!http://axschema.org/pref/languaget
first_namet	last_nameR.t t@iR/tlocaleR1sopenid.claimed_idt
claimed_id(terrorRDt
set_exceptionRRR4RFReRdRtlowerRER[R\R^t
set_result(
R;RtresponseR.RkR/RlRmR1Rptusert
name_partsRq((RjR;s2/usr/lib64/python2.7/site-packages/tornado/auth.pyRJ�sT	
	






cC�s
tj�S(s�Returns the `.AsyncHTTPClient` instance to be used for auth requests.

        May be overridden by subclasses to use an HTTP client other than
        the default.
        (RtAsyncHTTPClient(R;((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyRH2sN(RRt__doc__RRR=R,RMR6RJRH(((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR-�s0	<t
OAuthMixincB�s�eZdZeddddd��Zedd��Zddd�Zd�Z	d�Z
d�Zd�Zed��Z
d	�Zd
�Zidd�Zd
�ZRS(s+Abstract implementation of OAuth 1.0 and 1.0a.

    See `TwitterMixin` below for an example implementation.

    Class attributes:

    * ``_OAUTH_AUTHORIZE_URL``: The service's OAuth authorization url.
    * ``_OAUTH_ACCESS_TOKEN_URL``: The service's OAuth access token url.
    * ``_OAUTH_VERSION``: May be either "1.0" or "1.0a".
    * ``_OAUTH_NO_CALLBACKS``: Set this to True if the service requires
      advance registration of callbacks.

    Subclasses must also override the `_oauth_get_user_future` and
    `_oauth_consumer_token` methods.
    cC�s�|r't|dt�r'td��n|dkrB|j�}nt|dd�dkr�|j|jd|d|�tj|j	|j
||��n.|j|j�tj|j	|j
||��dS(s<Redirects the user to obtain OAuth authorization for this service.

        The ``callback_uri`` may be omitted if you have previously
        registered a callback URI with the third-party service.  For
        some services (including Friendfeed), you must use a
        previously-registered callback URI and cannot specify a
        callback via this method.

        This method sets a cookie called ``_oauth_request_token`` which is
        subsequently used (and cleared) in `get_authenticated_user` for
        security purposes.

        Note that this method is asynchronous, although it calls
        `.RequestHandler.finish` for you so it may not be necessary
        to pass a callback or use the `.Future` it returns.  However,
        if this method is called from a function decorated with
        `.gen.coroutine`, you must call it with ``yield`` to keep the
        response from being closed prematurely.

        .. versionchanged:: 3.1
           Now returns a `.Future` and takes an optional callback, for
           compatibility with `.gen.coroutine`.
        t_OAUTH_NO_CALLBACKSs,This service does not support oauth_callbackt_OAUTH_VERSIONs1.0aR<textra_paramsN(tgetattrRt	ExceptionRRHRIt_oauth_request_token_urlR$R%t_on_request_tokent_OAUTH_AUTHORIZE_URL(R;R<R~RKR((s2/usr/lib64/python2.7/site-packages/tornado/auth.pytauthorize_redirectKs&
	cC�s5|}tj|jd��}|jdd�}|jd�}|s\|jtd��dS|jd�g|jd�D]}t	j
tj|��^qy\}}	||kr�|jtd��dStd|d	|	�}
|r�||
d
<n|dkr	|j�}n|j
|j|
�tj|j|��dS(sGets the OAuth authorized user and access token.

        This method should be called from the handler for your
        OAuth callback URL to complete the registration process. We run the
        callback with the authenticated user dictionary.  This dictionary
        will contain an ``access_key`` which can be used to make authorized
        requests to this service on behalf of the user.  The dictionary will
        also contain other fields such as ``name``, depending on the service
        used.
        toauth_tokentoauth_verifiert_oauth_request_tokens"Missing OAuth request token cookieNt|s#Request token does not match cookietkeytsecrettverifier(Rtutf8RdRt
get_cookieRsRtclear_cookieR^tbase64t	b64decodeRERHRIt_oauth_access_token_urlR$R%t_on_access_token(R;RRKRtrequest_keyR�trequest_cookietit
cookie_keyt
cookie_secretttoken((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyRMzs*	

:	

cC�s1|j�}|j}tdtj|d�dddtttj���dtjtj	t
j�j��dd�}t
|d	d
�d
kr�|dkr�d|d<n(|r�tj|jj�|�|d<n|r�|j|�nt|d
||�}nt|d
||�}||d<|dtj|�S(Ntoauth_consumer_keyR�toauth_signature_methods	HMAC-SHA1toauth_timestamptoauth_noncet
oauth_versions1.0R}s1.0atoobtoauth_callbacktGETtoauth_signatureR3(t_oauth_consumer_tokent_OAUTH_REQUEST_TOKEN_URLRERt
to_basestringRtintttimetbinasciitb2a_hextuuidtuuid4tbytesRRVRWR4RXRYt_oauth10a_signaturet_oauth_signatureR9R:(R;R<R~tconsumer_tokenRLR&t	signature((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��s(	!	

cC�s|jrtd|j��nt|j�}tjtj|d��dtjtj|d��}|jd|�t	d|d�}|dkr�|j
|dtj|��|�dS|r�t
j|jj�|�|d	<n|j|dtj|��|�dS(
NsCould not get request token: %sR�R�R�R�R�R�R3R�(RrR�t_oauth_parse_responseRDR�t	b64encodeRR�t
set_cookieREtfinishR9R:RVRWR4RXR7(R;t
authorize_urlR<RRvt
request_tokentdataR&((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��s 	c
C�s|j�}|j}tdtj|d�dtj|d�dddtttj���dtjtj	t
j�j��dd	�}d
|kr�|d
|d<nt
|dd
�d
kr�t|d|||�}nt|d|||�}||d<|dtj|�S(NR�R�R�R�s	HMAC-SHA1R�R�R�s1.0R�R�R}s1.0aR�R�R3(R�t_OAUTH_ACCESS_TOKEN_URLRERR�RR�R�R�R�R�R�R�RR�R�R9R:(R;R�R�RLR&R�((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��s$	!		
cC�s[|jr |jtd��dSt|j�}|j|�jtj|j	||��dS(NsCould not fetch access token(
RrRsRR�RDt_oauth_get_user_futureR#R$R%t_on_oauth_get_user(R;RRvtaccess_token((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��s	cC�s
t��dS(s�Subclasses must override this to return their OAuth consumer keys.

        The return value should be a `dict` with keys ``key`` and ``secret``.
        N(tNotImplementedError(R;((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��scC�s|j||�dS(sSubclasses must override this to get basic information about the
        user.

        Should return a `.Future` whose result is a dictionary
        containing information about the user, which may have been
        retrieved by using ``access_token`` to make a request to the
        service.

        The access token will be added to the returned dictionary to make
        the result of `get_authenticated_user`.

        For backwards compatibility, the callback-based ``_oauth_get_user``
        method is also supported.
        N(t_oauth_get_user(R;R�R((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��scC�s
t��dS(N(R�(R;R�R((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR�scC�sm|j�dk	r)|j|j��dS|j�}|sR|jtd��dS||d<|j|�dS(NsError getting userR�(t	exceptionRRsRRRu(R;R�Rtuser_futureRw((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR�s
R�c	
C�s|j�}tdtj|d�dtj|d�dddtttj���dtjtjt	j
�j��dd	�}i}|j|�|j|�t
|d
d�dkr�t|||||�}nt|||||�}tj|�|d<|S(
s�Returns the OAuth parameters as a dict for the given request.

        parameters should include all POST arguments and query string arguments
        that will be sent with the request.
        R�R�R�R�s	HMAC-SHA1R�R�R�s1.0R}s1.0aR�(R�RERR�RR�R�R�R�R�R�R�RYRR�R�(	R;RLR�t
parametersRBR�t	base_argsR&R�((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyt_oauth_request_parameterss$!	

	cC�s
tj�S(s�Returns the `.AsyncHTTPClient` instance to be used for auth requests.

        May be overridden by subclasses to use an HTTP client other than
        the default.
        (RRy(R;((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyRH.sN(RRRzRRR�R,RMR�R�R�R�R�R�R�R�R�RH(((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR{;s"-!							tOAuth2Mixinc	B�sJeZdZedddddddd��Zdddddd�ZRS(s#Abstract implementation of OAuth 2.0.

    See `FacebookGraphMixin` or `GoogleOAuth2Mixin` below for example
    implementations.

    Class attributes:

    * ``_OAUTH_AUTHORIZE_URL``: The service's authorization url.
    * ``_OAUTH_ACCESS_TOKEN_URL``:  The service's access token url.
    tcodec	C�sqi|d6|d6|d6}|r1|j|�n|rMdj|�|d<n|jt|j|��|�dS(s�Redirects the user to obtain OAuth authorization for this service.

        Some providers require that you register a redirect URL with
        your application instead of passing one via this method. You
        should call this method to log the user in, and then call
        ``get_authenticated_user`` in the handler for your
        redirect URL to complete the authorization process.

        .. versionchanged:: 3.1
           Returns a `.Future` and takes an optional callback.  These are
           not strictly necessary as this method is synchronous,
           but they are supplied for consistency with
           `OAuthMixin.authorize_redirect`.
        tredirect_urit	client_idt
response_typeRntscopeN(RYR\R7R	R�(	R;R�R�t
client_secretR~RR�R�R&((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR�Bs
c	C�sM|j}td|d|d|d|�}|r@|j|�nt||�S(NR�R�R�R�(R�RERYR	(R;R�R�R�R�R~RLR&((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR�as		N(RRRzRRR�R�(((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR�7s
tTwitterMixincB�s�eZdZdZdZdZdZeZdZ	e
ddd��Ze
dddd��Zd�Zd	�Zejd
��ZRS(s&Twitter OAuth authentication.

    To authenticate with Twitter, register your application with
    Twitter at http://twitter.com/apps. Then copy your Consumer Key
    and Consumer Secret to the application
    `~tornado.web.Application.settings` ``twitter_consumer_key`` and
    ``twitter_consumer_secret``. Use this mixin on the handler for the
    URL you registered as your application's callback URL.

    When your application is set up, you can use this mixin like this
    to authenticate the user with Twitter and get access to their stream:

    .. testcode::

        class TwitterLoginHandler(tornado.web.RequestHandler,
                                  tornado.auth.TwitterMixin):
            @tornado.gen.coroutine
            def get(self):
                if self.get_argument("oauth_token", None):
                    user = yield self.get_authenticated_user()
                    # Save the user using e.g. set_secure_cookie()
                else:
                    yield self.authorize_redirect()

    .. testoutput::
       :hide:

    The user object returned by `~OAuthMixin.get_authenticated_user`
    includes the attributes ``username``, ``name``, ``access_token``,
    and all of the custom Twitter user attributes described at
    https://dev.twitter.com/docs/api/1.1/get/users/show
    s+https://api.twitter.com/oauth/request_tokens*https://api.twitter.com/oauth/access_tokens'https://api.twitter.com/oauth/authorizes*https://api.twitter.com/oauth/authenticateshttps://api.twitter.com/1.1cC�sD|j�}|j|jd|�tj|j|jd|��dS(saJust like `~OAuthMixin.authorize_redirect`, but
        auto-redirects if authorized.

        This is generally the right interface to use if you are using
        Twitter for single-sign on.

        .. versionchanged:: 3.1
           Now returns a `.Future` and takes an optional callback, for
           compatibility with `.gen.coroutine`.
        R<N(RHRIR�R$R%R�t_OAUTH_AUTHENTICATE_URLR(R;R<Rthttp((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR=�s
c
K�s6|jd�s|jd�r'|}n|j|d}|r�i}|j|�|j|p`i�|d
k	rvdnd}|j|||d|�}	|j|	�n|r�|dtj|�7}n|j�}
tj	|j
|�}|d
k	r|
j|dddtj|�d	|�n|
j|d	|�d
S(s!Fetches the given API path, e.g., ``statuses/user_timeline/btaylor``

        The path should not include the format or API version number.
        (we automatically use JSON format and API version 1).

        If the request is a POST, ``post_args`` should be provided. Query
        string arguments should be given as keyword arguments.

        All the Twitter methods are documented at http://dev.twitter.com/

        Many methods require an OAuth access token which you can
        obtain through `~OAuthMixin.authorize_redirect` and
        `~OAuthMixin.get_authenticated_user`. The user returned through that
        process includes an 'access_token' attribute that can be used
        to make authenticated requests via this method. Example
        usage:

        .. testcode::

            class MainHandler(tornado.web.RequestHandler,
                              tornado.auth.TwitterMixin):
                @tornado.web.authenticated
                @tornado.gen.coroutine
                def get(self):
                    new_entry = yield self.twitter_request(
                        "/statuses/update",
                        post_args={"status": "Testing Tornado Web Server"},
                        access_token=self.current_user["access_token"])
                    if not new_entry:
                        # Call failed; perhaps missing permission?
                        yield self.authorize_redirect()
                        return
                    self.finish("Posted a message!")

        .. testoutput::
           :hide:

        shttp:shttps:s.jsonRCR�RBR3RDRN(Ret_TWITTER_BASE_URLRYRR�R9R:RHR$R%t_on_twitter_requestRI(R;tpathRR�t	post_argsR&RLtall_argsRBtoauthR�t
http_callback((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyttwitter_request�s&)	
!
cC�sP|jr3|jtd|j|jjf��dS|jtj|j��dS(NsError response %s fetching %s(	RrRsRR4RLRuRtjson_decodeRD(R;RRv((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��s			cC�sA|jdd�|jdd�td|jdd|jd�S(Nttwitter_consumer_keys
Twitter OAuthttwitter_consumer_secretR�R�(trequire_settingREtsettings(R;((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��s

cc�s@|jdd|�V}|r-|d|d<ntj|��dS(Ns/account/verify_credentialsR�tscreen_nameR1(R�RtReturn(R;R�Rw((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��s
N(RRRzR�R�R�R�RR|R�RRR=R,R�R�R�Rt	coroutineR�(((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR�ps @		tGoogleOAuth2MixincB�sGeZdZdZdZeZdZed��Z	d�Z
d�ZRS(sGoogle authentication using OAuth2.

    In order to use, register your application with Google and copy the
    relevant parameters to your application settings.

    * Go to the Google Dev Console at http://console.developers.google.com
    * Select a project, or create a new one.
    * In the sidebar on the left, select APIs & Auth.
    * In the list of APIs, find the Google+ API service and set it to ON.
    * In the sidebar on the left, select Credentials.
    * In the OAuth section of the page, select Create New Client ID.
    * Set the Redirect URI to point to your auth handler
    * Copy the "Client secret" and "Client ID" to the application settings as
      {"google_oauth": {"key": CLIENT_ID, "secret": CLIENT_SECRET}}

    .. versionadded:: 3.2
    s)https://accounts.google.com/o/oauth2/auths*https://accounts.google.com/o/oauth2/tokentgoogle_oauthc	C�s�|j�}tji|d6|d6|j|jdd6|j|jdd6dd6�}|j|jtj|j	|�d	d
didd
6d|�dS(s_Handles the login for the Google user, returning a user object.

        Example usage:

        .. testcode::

            class GoogleOAuth2LoginHandler(tornado.web.RequestHandler,
                                           tornado.auth.GoogleOAuth2Mixin):
                @tornado.gen.coroutine
                def get(self):
                    if self.get_argument('code', False):
                        user = yield self.get_authenticated_user(
                            redirect_uri='http://your.site.com/auth/google',
                            code=self.get_argument('code'))
                        # Save the user with e.g. set_secure_cookie
                    else:
                        yield self.authorize_redirect(
                            redirect_uri='http://your.site.com/auth/google',
                            client_id=self.settings['google_oauth']['key'],
                            scope=['profile', 'email'],
                            response_type='code',
                            extra_params={'approval_prompt': 'auto'})

        .. testoutput::
           :hide:

        R�R�R�R�R�R�tauthorization_codet
grant_typeRBRCtheaderss!application/x-www-form-urlencodedsContent-TypeRDN(
RHR9R:R�t_OAUTH_SETTINGS_KEYRIR�R$R%R�(R;R�R�RR�RD((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyRMs	
cC�sM|jr*|jtdt|���dStj|j�}|j|�dS(s7Callback function for the exchange to the access token.sGoogle auth error: %sN(RrRsRRRR�RDRu(R;RRvR&((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR�Fs
	cC�s
tj�S(s�Returns the `.AsyncHTTPClient` instance to be used for auth requests.

        May be overridden by subclasses to use an HTTP client other than
        the default.
        (RRy(R;((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyRHOs(RRRzR�R�RR|R�R,RMR�RH(((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR�s*		tFacebookGraphMixincB�sqeZdZdZdZeZdZed
d��Z
d�Zd�Zed
d
d��Z
d�Zd	�ZRS(s;Facebook authentication using the new Graph API and OAuth2.s.https://graph.facebook.com/oauth/access_token?s&https://www.facebook.com/dialog/oauth?shttps://graph.facebook.comc
	C�s�|j�}i|d6|d6|d6|d6}tddddd	d
dg�}	|re|	j|�n|j|j|�tj|j|||||	��dS(
sdHandles the login for the Facebook user, returning a user object.

        Example usage:

        .. testcode::

            class FacebookGraphLoginHandler(tornado.web.RequestHandler,
                                            tornado.auth.FacebookGraphMixin):
              @tornado.gen.coroutine
              def get(self):
                  if self.get_argument("code", False):
                      user = yield self.get_authenticated_user(
                          redirect_uri='/auth/facebookgraph/',
                          client_id=self.settings["facebook_api_key"],
                          client_secret=self.settings["facebook_secret"],
                          code=self.get_argument("code"))
                      # Save the user with e.g. set_secure_cookie
                  else:
                      yield self.authorize_redirect(
                          redirect_uri='/auth/facebookgraph/',
                          client_id=self.settings["facebook_api_key"],
                          extra_params={"scope": "read_stream,offline_access"})

        .. testoutput::
           :hide:

        R�R�R�R�tidR.RlRmRptpicturetlinkN(RHRZRYRIR�R$R%R�(
R;R�R�R�R�Rtextra_fieldsR�R&tfields((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyRM_s
c	
C�s�|jr*|jtdt|���dStjtj|j��}i|ddd6|jd�d6}|j	dddt
j|j|||�d|ddd	j
|��dS(
NsFacebook auth error: %sR�i����texpiresR�s/meRR�RT(RrRsRRRtparse_qs_bytest
native_strRDtgettfacebook_requestR$R%t_on_get_user_infoR\(	R;R�R�R�RR�RvR&tsession((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��s		
cC�s�|dkr|jd�dSi}x!|D]}|j|�||<q*W|ji|dd6|jd�d6�|j|�dS(NR�R�tsession_expires(RRuR�RY(R;RR�R�Rwtfieldmaptfield((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��s

(c	K�s�|j|}i}|r3||d<|j|�n|rS|dtj|�7}ntj|j|�}|j�}|dk	r�|j	|dddtj|�d|�n|j	|d|�dS(s�Fetches the given relative API path, e.g., "/btaylor/picture"

        If the request is a POST, ``post_args`` should be provided. Query
        string arguments should be given as keyword arguments.

        An introduction to the Facebook Graph API can be found at
        http://developers.facebook.com/docs/api

        Many methods require an OAuth access token which you can
        obtain through `~OAuth2Mixin.authorize_redirect` and
        `get_authenticated_user`. The user returned through that
        process includes an ``access_token`` attribute that can be
        used to make authenticated requests via this method.

        Example usage:

        ..testcode::

            class MainHandler(tornado.web.RequestHandler,
                              tornado.auth.FacebookGraphMixin):
                @tornado.web.authenticated
                @tornado.gen.coroutine
                def get(self):
                    new_entry = yield self.facebook_request(
                        "/me/feed",
                        post_args={"message": "I am posting from my Tornado application!"},
                        access_token=self.current_user["access_token"])

                    if not new_entry:
                        # Call failed; perhaps missing permission?
                        yield self.authorize_redirect()
                        return
                    self.finish("Posted a message!")

        .. testoutput::
           :hide:

        The given path is relative to ``self._FACEBOOK_BASE_URL``,
        by default "https://graph.facebook.com".

        .. versionchanged:: 3.1
           Added the ability to override ``self._FACEBOOK_BASE_URL``.
        R�R3RBRCRDRN(
t_FACEBOOK_BASE_URLRYR9R:R$R%t_on_facebook_requestRHRRI(	R;R�RR�R�R&RLR�R�((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��s.

!
cC�sP|jr3|jtd|j|jjf��dS|jtj|j��dS(NsError response %s fetching %s(	RrRsRR4RLRuRR�RD(R;RRv((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��s
	cC�s
tj�S(s�Returns the `.AsyncHTTPClient` instance to be used for auth requests.

        May be overridden by subclasses to use an HTTP client other than
        the default.
        (RRy(R;((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyRH�sN(RRRzR�R�RR|R�R,RRMR�R�R�R�RH(((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR�Xs-		<	cC�s.tj|�}|d \}}}|j�d|j�|}	g}
|
j|j��|
j|	�|
jdjd�t|j��D���djd�|
D��}tj|d�g}|jtj|r�|dnd��dj|�}
t	j
|
tj|�tj�}t
j|j��d S(	sxCalculates the HMAC-SHA1 OAuth signature for the given request.

    See http://oauth.net/core/1.0/#signing_process
    is://t&cs�s1|]'\}}d|tt|��fVqdS(s%s=%sN(t
_oauth_escapeR(R>R?R@((s2/usr/lib64/python2.7/site-packages/tornado/auth.pys	<genexpr>	scs�s|]}t|�VqdS(N(R�(R>R((s2/usr/lib64/python2.7/site-packages/tornado/auth.pys	<genexpr>sR�Rbi����(RVRtR[tupperR\tsortedRGRR�thmactnewthashlibtsha1R�t
b2a_base64tdigest(R�RBRLR�R�tpartstschemetnetlocR�tnormalized_urlt
base_elemstbase_stringt	key_elemsR�thash((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR��s
&!cC�sLtj|�}|d \}}}|j�d|j�|}	g}
|
j|j��|
j|	�|
jdjd�t|j��D���djd�|
D��}tjt	j
|ddd��g}|jtj|r�t	j
|ddd�nd	��dj|�}
tj|
tj|�t
j�}tj|j��d
 S(s~Calculates the HMAC-SHA1 OAuth 1.0a signature for the given request.

    See http://oauth.net/core/1.0a/#signing_process
    is://R�cs�s1|]'\}}d|tt|��fVqdS(s%s=%sN(R�R(R>R?R@((s2/usr/lib64/python2.7/site-packages/tornado/auth.pys	<genexpr>!scs�s|]}t|�VqdS(N(R�(R>R((s2/usr/lib64/python2.7/site-packages/tornado/auth.pys	<genexpr>$sR�tsafet~Rbi����(RVRtR[R�R\R�RGRR�R9tquoteR�R�R�R�R�R�R�(R�RBRLR�R�R�R�RR�RRRRR�R((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR�s
%5!cC�s4t|t�r!|jd�}ntj|dd�S(Nsutf-8RR(t
isinstanceR
tencodeR9R(tval((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyR�-sc�sstj|�}tj|dt��td�ddd�dd�}d�|j��fd��D��|S(	Ntkeep_blank_valuesR�R�iR�toauth_token_secretc3�s/|]%}|�kr|�|dfVqdS(iN((R>R?(tptspecial(s2/usr/lib64/python2.7/site-packages/tornado/auth.pys	<genexpr>=s(soauth_tokenR
(RR�RVtparse_qsRRERY(RDR�((RRs2/usr/lib64/python2.7/site-packages/tornado/auth.pyR�3s% (7Rzt
__future__RRRRR�R�R$R�R�R�R�ttornado.concurrentRRttornadoRRRttornado.httputilR	ttornado.logR
ttornado.stack_contextRttornado.utilRR
RRVtImportErrorturllib.parsetparseR9turllibtlongt	NameErrorR�R�RRR,tobjectR-R{R�R�R�R�RR�R�R�R�(((s2/usr/lib64/python2.7/site-packages/tornado/auth.pyt<module>AsR"



			��9�S�	

Zerion Mini Shell 1.0