cA4dZddlZddlZddlZddlZddlZddlmZddlm Z m Z m ZddlmZ ddlmZmZn#e$r ddlmZmZYnwxYwdZd Zejd ejZejd Zd Zejd Zd(dZ dZ dZ dZ dZ!e"ee"dzZ#dZ$dZ%dZ&dZ'defdZ(dZ)dZ*defdZ+dZ,d)d Z-d!Z.d*d#Z/Gd$d%e0Z1Gd&d'Z2dS)+z| oauthlib.common ~~~~~~~~~~~~~~ This module provides data structures and utilities common to all implementations of OAuth. N)quoteunquote urlencode) get_debug) SystemRandomrandbits)r getrandbits>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789z_ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}z&([^&;]*(?:password|token)[^=]*=)[^&;]+z&%[^0-9A-Fa-f]|%[0-9A-Fa-f][^0-9A-Fa-f]zAABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-oauthlib/ct|tr|dn|}t||}t|tr|d}|SNutf-8) isinstancestrencode_quotebytesdecode)ssafes 1/usr/lib/python3/dist-packages/oauthlib/common.pyrr+s^'3//6QAq$A!U HHW   Hcxt|}t|tr|d}|Sr)_unquoterrr)rs rrr5s7 A!U HHW   Hrct|}t|}t|tr|S|dSr)encode_params_utf8 _urlencoderrr)params utf8_params urlencodeds rrr?sH$V,,KK((J*c""*  )))rcg}|D]p\}}|t|tr|dn|t|tr|dn|fq|S)ziEnsures that all parameters in a list of 2-element tuples are encoded to bytestrings using UTF-8 r)appendrrr)r encodedkvs rrrHsG==1!+As!3!3 :AHHW   !+As!3!3 :AHHW   < = = = = Nrcg}|D]p\}}|t|tr|dn|t|tr|dn|fq|S)zfEnsures that all parameters in a list of 2-element tuples are decoded to unicode using UTF-8. r)r$rrr)r decodedr&r's rdecode_params_utf8r*TsG??1!+Au!5!5  ? ? ? ? Nrz=&;:%+~,*@!()/?'$c(|rCt|tks+d}t|t|tz |fzt|rtdt j|d}t|S)aDecode a query string in x-www-form-urlencoded format into a sequence of two-element tuples. Unlike urlparse.parse_qsl(..., strict_parsing=True) urldecode will enforce correct formatting of the query string by validation. If validation fails a ValueError will be raised. urllib.parse_qsl will only raise errors if any of name-value pairs omits the equals sign. zError trying to decode a non urlencoded string. Found invalid characters: %s in the string: '%s'. Please ensure the request/response body is x-www-form-urlencoded.z%Invalid hex encoding in query string.Tkeep_blank_values)setr" ValueErrorINVALID_HEX_PATTERNsearchurlparse parse_qslr*)queryerrorr s r urldecoder6cs CSZZ:--* #e**z"95!AABBB !!%((B@AAA  > > >F f % %%rct|ttfr# t|}n#t$rd}YnwxYwt |drw t |tt|t r|n|}t|}n!#t$rd}Ynt$rd}YnwxYwd}|S)a*Extract parameters and return them as a list of 2-tuples. Will successfully extract parameters from urlencoded query strings, dicts, or lists of 2-tuples. Empty strings/dicts/lists will return an empty list of parameters. Any other input will result in a return value of None. N__iter__) rrrr6r/hasattrdictlistitemsr* TypeError)rawr s rextract_paramsr?s#s|$$ s^^FF   FFF  j ! !  0 III C)>)>G#))+++CHHF'//FF    FFF   FFF   Ms$. ==B(( C6 CCcrtttdtzS)aGenerate pseudorandom nonce that is unlikely to repeat. Per `section 3.3`_ of the OAuth 1 RFC 5849 spec. Per `section 3.2.1`_ of the MAC Access Authentication spec. A random 64-bit number is appended to the epoch timestamp for both randomness and to decrease the likelihood of collisions. .. _`section 3.2.1`: https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-3.2.1 .. _`section 3.3`: https://tools.ietf.org/html/rfc5849#section-3.3 @)rr generate_timestamprrgenerate_noncerDs, s8B<<  #5#7#77 8 88rc\tttjS)aDGet seconds since epoch (UTC). Per `section 3.3`_ of the OAuth 1 RFC 5849 spec. Per `section 3.2.1`_ of the MAC Access Authentication spec. .. _`section 3.2.1`: https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-3.2.1 .. _`section 3.3`: https://tools.ietf.org/html/rfc5849#section-3.3 )rinttimerCrrrBrBs  s49;;  rctdfdt|DS)aXGenerates a non-guessable OAuth token OAuth (1 and 2) does not specify the format of tokens except that they should be strings of random characters. Tokens should not be guessable and entropy when generating the random characters is important. Which is why SystemRandom is used instead of the default random.choice method. c3BK|]}VdSN)choice).0xcharsrands r z!generate_token..s/==!4;;u%%======r)rjoinrange)lengthrPrQs `@rgenerate_tokenrVs? >>D 77=====uV}}=== = ==rcddl}tj}|j|tj|jzd}||j|||d}t|d}|S)Nr)seconds)scopeexpRS256UTF-8) jwtdatetimeutcnowrY timedelta expires_inupdateclaimsr to_unicode) private_pemrequestr]nowrctokens rgenerate_signed_tokenrisJJJ   " " $ $CX'0BCCCCF  MM'.!!! JJv{G 4 4E ug & &E Lrc<ddl}|||dgS)Nrr[) algorithms)r]r) public_pemrhr]s rverify_signed_tokenrms%JJJ ::eZWI: > >>rc"t||S)zGenerates an OAuth client_id OAuth 2 specify the format of client_id in https://tools.ietf.org/html/rfc6749#appendix-A. )rV)rUrPs rgenerate_client_idros &% ( ((rct|tr|}tj|d}||t |S)z)Extend a query with a list of two-tuples.Tr,)rr:r<r2r3extendr)r4r queryparamss radd_params_to_qsrssX&$ $UdCCCKv [ ! !!rFctj|\}}}}}}|rt||}nt||}tj||||||fS)z5Add a list of two-tuples to the uri query components.)r2rs urlunparse) urir fragmentschnetpathparr4fras radd_params_to_urir}se&.&7&<&<#CdC0sF++ //  S$UC@ A AArct|t|krdSd}t||D]'\}}|t|t|z z}(|dkS)a Near-constant time string comparison. Used in order to avoid timing attacks on sensitive information such as secret keys during request verification (`rootLabs`_). .. _`rootLabs`: http://rdist.root.org/2010/01/07/timing-independent-array-comparison/ Fr)lenzipord)abresultrOys rsafe_string_equalsrsf 1vvQu FAq ""1#a&&3q66/! Q;rr\cxt|tr|St|trt|St|drk t |t|dr|}fd|DS#t $rYnt$rfd|DcYSwxYw|S)z:Convert a number of different types of objects to unicode.)encodingr8r<cTi|]$\}}t|t|%SrCrd)rNr&r'rs r zto_unicode.."s3VVVAJq(++Z8-D-DVVVrc38K|]}t|VdSrLr)rNirs rrRzto_unicode..s-::Jq(++::::::r)rrrr9r:r<r=r/)datars `rrdrds$ $,4(++++tZ  W W JJJtW%% $zz||VVVVQUVVV V    D ; ; ;::::T::: : : : ; KsB B7B76B7cXeZdZdZiZdZdZfdZfdZd dZ fdZ fd Z xZ S) CaseInsensitiveDictz3Basic case insensitive dict with strings only keys.cHd|D|_|D] }||||<dS)Nc8i|]}||SrC)lower)rNr&s rrz0CaseInsensitiveDict.__init__...s"111qaggii111r)proxy)selfrr&s r__init__zCaseInsensitiveDict.__init__-s?11D111   A1gDGG  rc8||jvSrL)rr)rr&s r __contains__z CaseInsensitiveDict.__contains__2swwyyDJ&&rc|j|}t||j|=dSrL)rrsuper __delitem__rr&key __class__s rrzCaseInsensitiveDict.__delitem__5sGj# C   Jqwwyy ! ! !rc|j|}t|SrL)rrr __getitem__rs rrzCaseInsensitiveDict.__getitem__:s/j#ww""3'''rNc||vr||n|SrLrC)rr&defaults rgetzCaseInsensitiveDict.get>st))tAww0rct||||j|<dSrL)r __setitem__rr)rr&r'rs rrzCaseInsensitiveDict.__setitem__As7 Aq!!! ! 17799rctj|i|t|i|D]}||j|<dSrL)rrbr:rr)rargskwargsr&rs rrbzCaseInsensitiveDict.updateEs[''''t&v&& & &A$%DJqwwyy ! ! & &rrL) __name__ __module__ __qualname____doc__rrrrrrrrb __classcell__)rs@rrr's== E '''""""" (((((1111"""""&&&&&&&&&rrcleZdZdZ d dZdZdZedZed Z ed Z dS) Requesta:A malleable representation of a signable HTTP request. Body argument may contain any data, but parameters will only be decoded if they are one of: * urlencoded query string * dict * list of 2-tuples Anything else will be treated as raw body data to be passed through unmolested. GETNrc`fd}|||_|||_t||pi|_|||_t |j|_g|_i|_iddddddddddddddd dd dd dd dd ddddddddddddddddddddddddd |_ |j tt|j |j t|jpgdS)Nc,rt|n|SrLr)rOrs rz"Request.__init__..]shE:a222Ar access_tokenclient client_id client_secretcodecode_challengecode_challenge_method code_verifierextra_credentials grant_type redirect_uri refresh_token request_token response_typerYscopesstate) rhusertoken_type_hint response_modenoncedisplaypromptrcmax_age ui_locales id_token_hint login_hint acr_values)rv http_methodrheadersbodyr? decoded_body oauth_params validator_log_paramsrbr:r6 uri_query)rrvrrrrrs ` rrzRequest.__init__ZsFEEE6#;;!6+..*66'-R+@+@AA F4LL *4955! D! d!  !  T ! D ! d !  $T!  T!  !  $!  D!  T!  T!  T!  T! d!! " T#! $#"!A! ! !  D D4>!:!:;;<<< D!2!8b99:::::rcL||jvr |j|St|rL)rAttributeError)rnames r __getattr__zRequest.__getattr__s* 4<  <% % && &rc tsdS|j}|j}|r(tdt |}d|vrd|d<d|j|j ||S)Nzz  Authorizationz zF) rrrcopySANITIZE_PATTERNsubrformatrvr)rrrs r__repr__zRequest.__repr__s{{ 211y,##%%  D#''TCCD g % %'4GO $W^^ Hd&77 7rc>tj|jjSrL)r2rvr4rs rrzRequest.uri_querys **00rcL|jsgStj|jddS)NT)r-strict_parsing)rr2r3rs ruri_query_paramszRequest.uri_query_paramss4~ I!$.D15777 7rctjt}d|jpg|jzD}|D]}||xxdz cc<d|DS)Nc3&K|] }|dV dS)rNrC)rNps rrRz+Request.duplicate_params..sBPPaDPPPPPPrrc$g|] \}}|dk |S)rrC)rNr&cs r z,Request.duplicate_params..s!999da1q55555r) collections defaultdictrFrrr<)r seen_keysall_keysr&s rduplicate_paramszRequest.duplicate_paramss+C00 PP"/529NNPPP  A aLLLA LLLL99ioo//9999r)rNNr) rrrrrrrpropertyrrrrCrrrrKs  CG!0;0;0;0;d''' 7 7 711X177X7 ::X:::rr)r )F)r\)3rrr^loggingrerG urllib.parseparser2rrrrrrrJrsecretsrr ImportErrorrandomr UNICODE_ASCII_CHARACTER_SETCLIENT_ID_CHARACTER_SETcompile IGNORECASErr0 always_safe getLoggerlogrr*r.r"r6r?rDrBrVrirmrorsr}rrdr:rrrCrrrs =.........===<<<<<<<<<<= ,N2:GWW bj!JKK" g ##       ***      S  $8 9 9 9 &&&B: 9 9 9 ! ! !$? > > > >$??? !(?))))"""BBBB$2!&!&!&!&!&$!&!&!&He:e:e:e:e:e:e:e:e:e:s7 AA