bl+dZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z ddl mZGd d eZ dd ZdZddZddZddZdZdZGddZGddeZdS)z oauthlib.oauth2.rfc6749.tokens ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This module contains methods for adding two types of access tokens to requests. - Bearer https://tools.ietf.org/html/rfc6750 - MAC https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01 N) b2a_base64)urlparse)common)add_params_to_qsadd_params_to_uri)utilsceZdZd fd ZedZedZedZedZedZ edZ ed Z xZ S) OAuth2TokenNc^t|d|_d|vr4|dr,tt j|d|_|=tt j||_|j|j|_dSdS|j|_dS)Nscope)super__init__ _new_scopesetr scope_to_list _old_scope)selfparams old_scope __class__s @/usr/lib/python3/dist-packages/oauthlib/oauth2/rfc6749/tokens.pyrzOAuth2Token.__init__s     f   !%"5fWo"F"FGGDO  !%"5i"@"@AADO&#'/'& #oDOOOc"|j|jkSN)rrrs r scope_changedzOAuth2Token.scope_changed&s$/11rc4tj|jSr)r list_to_scoperrs rrzOAuth2Token.old_scope*"4?333rc*t|jSr)listrrs r old_scopeszOAuth2Token.old_scopes.DO$$$rc4tj|jSr)r rrrs rr zOAuth2Token.scope2r rc*t|jSr)r"rrs rscopeszOAuth2Token.scopes6r$rc:t|j|jz Sr)r"rrrs rmissing_scopeszOAuth2Token.missing_scopes:DOdo5666rc:t|j|jz Sr)r"rrrs radditional_scopeszOAuth2Token.additional_scopes>r*rr) __name__ __module__ __qualname__rpropertyrrr#r r'r)r, __classcell__)rs@rr r s . . . . . .22X244X4%%X%44X4%%X%77X777X77777rr hmac-sha-1c l|}tj|\} } |dkr tj} n4|dkr tj} ntd| dkr<|p8dtj | tj }n&tj }tj }t|\}}}}}}|r |dz|z}n|}|a| dkr[|d}t| |dd d}nd }g}| dkr||n*|||||||||| || | dkr||||pd d |d z}t)|t*r|d}t-j||d| }t|dd d}g}|d |z| dkr|d |z|d|z|r|d|z|r|d|z|d|z|pi}d||d<|S)a_Add an `MAC Access Authentication`_ signature to headers. Unlike OAuth 1, this HMAC signature does not require inclusion of the request payload/body, neither does it use a combination of client_secret and token_secret but rather a mac_key provided together with the access token. Currently two algorithms are supported, "hmac-sha-1" and "hmac-sha-256", `extension algorithms`_ are not supported. Example MAC Authorization header, linebreaks added for clarity Authorization: MAC id="h480djs93hd8", nonce="1336363200:dj83hs9s", mac="bhCQXTVyfj5cmA9uKkPFx1zeOXM=" .. _`MAC Access Authentication`: https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01 .. _`extension algorithms`: https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-7.1 :param token: :param uri: Request URI. :param key: MAC given provided by token endpoint. :param http_method: HTTP Request method. :param nonce: :param headers: Request headers as a dictionary. :param body: :param ext: :param hash_algorithm: HMAC algorithm provided by token endpoint. :param issue_time: Time when the MAC credentials were issued (datetime). :param draft: MAC authentication specification version. :return: headers dictionary with the authorization field added. r3z hmac-sha-256zunknown hash algorithmrz{}:{}?Nzutf-8r2 z MAC id="%s"zts="%s"z nonce="%s"z bodyhash="%s"zext="%s"zmac="%s"z, Authorization)upperr host_from_urilowerhashlibsha1sha256 ValueErrorformat generate_agergenerate_noncegenerate_timestamprencoderdigestdecodeappendjoin isinstancestrhmacnew)tokenurikey http_methodnonceheadersbodyexthash_algorithm issue_timedrafthostporthtsschnetpathparqueryfra request_uribodyhashbase base_stringsignheaders rprepare_mac_headerrhCsP##%%K$S))JD$-- L     > 1 1 N1222 zzC(::(F(F*0*?*A*ACC & ( (%''&.smm#CdC Sj5(   EQJJ{{7##aaggnn..//4;;GDD D zz E B EKK !!##$$$KK KKKK zz HKK r))D//D(K#s"jj!! 8C++G44a 8 8D dkkmm $ $SbS ) 0 0 9 9D F MM-%'((( zz i"n%%% MM,&'''2 o0111 ( j3&''' MM*t#$$$mG#yy00GO Nrc(t|d|fgS)aAdd a `Bearer Token`_ to the request URI. Not recommended, use only if client can't use authorization header or body. http://www.example.com/path?access_token=h480djs93hd8 .. _`Bearer Token`: https://tools.ietf.org/html/rfc6750 :param token: :param uri: access_token)r)rMrNs rprepare_bearer_urirks S^U$;"= > >>rc|pi}d|z|d<|S)zAdd a `Bearer Token`_ to the request URI. Recommended method of passing bearer tokens. Authorization: Bearer h480djs93hd8 .. _`Bearer Token`: https://tools.ietf.org/html/rfc6750 :param token: :param headers: z Bearer %sr8)rMrRs rprepare_bearer_headersrns!mG*U2GO Nrc(t|d|fgS)zAdd a `Bearer Token`_ to the request body. access_token=h480djs93hd8 .. _`Bearer Token`: https://tools.ietf.org/html/rfc6750 :param token: :param body: rj)r)rMrSs rprepare_bearer_bodyrps D^U$;"= > >>rFc(tjS)zp :param request: OAuthlib request. :type request: oauthlib.common.Request :param refresh_token: )rgenerate_token)request refresh_tokens rrandom_token_generatorrus  " ""rc fd}|S)z :param private_pem: c<|_tj|Sr)claimsrgenerate_signed_token)rskwargs private_pems rsigned_token_generatorz6signed_token_generator..signed_token_generators+KAAArrm)r{rzr|s`` rr|r|s0BBBBBB "!rcd}d|jvrf|jd}t|dkr&|ddkr|d}n|j}|S)z Helper function to extract a token from the request header. :param request: OAuthlib request. :type request: oauthlib.common.Request :return: Return the token or None if the Authorization header is malformed. Nr8rbearerr)rRgetsplitlenr;rj)rsrM split_headers rget_token_from_headerrs{ E'/))**?;;AACC |   ! !l1o&;&;&=&=&I&I OE$ Lrc&eZdZdZddZdZdZdS) TokenBasermFc td)N&Subclasses must implement this method.NotImplementedError)rrsrts r__call__zTokenBase.__call__s!"JKKKrc tdb :param request: OAuthlib request. :type request: oauthlib.common.Request rrrrss rvalidate_requestzTokenBase.validate_request  ""JKKKrc tdrrrs r estimate_typezTokenBase.estimate_typerrNF)r-r.r/ __slots__rrrrmrrrrsWILLLLLLLLLLLLrrc2eZdZdZ ddZd dZdZdZdS) BearerToken)request_validatortoken_generatorrefresh_token_generator expires_inNc^||_|pt|_|p|j|_|pd|_dS)Ni)rrurrr)rrrrrs rrzBearerToken.__init__s=!2.H2H # ;t'; $%,rFc d|vrtjdtt|jr||}n|j}||_|||dd}|jd|j|d<|rD|jr%|j |s |j|d<n| ||d<| |j pit|S) z Create a BearerToken, by default without refresh token. :param request: OAuthlib request. :type request: oauthlib.common.Request :param refresh_token: save_tokenzx`save_token` has been deprecated, it was not called internally.If you do, call `request_validator.save_token()` instead.Bearer)rjr token_typeN r rt)warningswarnDeprecationWarningcallablerrr'rHrtrrotate_refresh_tokenrupdateextra_credentialsr )rrsrtrzrrMs r create_tokenzBearerToken.create_token's' 6 ! ! MV, . . . DO $ $ )11JJJ'!0099$"   > % XXgn55E'N  O% O.CCGLL O)0)>o&&)-)E)Eg)N)No& W.4"5555!!!rcbt|}|j||j|S)r)rrvalidate_bearer_tokenr')rrsrMs rrzBearerToken.validate_requestQs5 &g..%;; 7>7,, ,rc|jdddddkrdS|jdSdS) rr8r2rrr N)rRrrr;rjrs rrzBearerToken.estimate_typeZsX ?   3 3 9 9# > >q A G G I IX U U1  ! -11r)NNNNr)r-r.r/rrrrrrmrrrrslI @D:>----("("("("T,,,     rr)NNNr2r3Nrr)r2r)__doc__r<rKrbinasciir urllib.parseroauthlibroauthlib.commonrrr2r dictr rhrkrnrprur|rrrrmrrrs !!!!!!????????*7*7*7*7*7$*7*7*7\"# &2"&jjjjZ ? ? ?     ? ? ? ?####"""(LLLLLLLL*LLLLL)LLLLLr