o an4@sdZddlZddlZddlZddlZddlZddlmZddlm Z m Z m ZddlmZzddlmZddlmZWneyOddlmZddlmZYnwd Zd Zed ejZed Zd ZedZd:ddZ ddZ ddZ ddZ ddZ!e"ee"dBZ#ddZ$ddZ%dd Z&d!d"Z'd#efd$d%Z(d&d'Z)d(d)Z*d#efd*d+Z+d,d-Z,d;d/d0Z-d1d2Z.dabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789z_ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}z&([^&;]*(?:password|token)[^=]*=)[^&;]+z&%[^0-9A-Fa-f]|%[0-9A-Fa-f][^0-9A-Fa-f]zAABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-oauthlib/cCs:t|tr |dn|}t||}t|tr|d}|SNutf-8) isinstancestrencode_quotebytesdecode)ssafer1/usr/lib/python3/dist-packages/oauthlib/common.pyr-s    rcCs t|}t|tr|d}|Sr )_unquoterrr)rrrrr7s  rcCs(t|}t|}t|tr|S|dSr )encode_params_utf8 _urlencoderrr)params utf8_params urlencodedrrrrAs   rcCLg}|D]\}}|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)rencodedkvrrrrJ rcCr)zfEnsures that all parameters in a list of 2-element tuples are decoded to unicode using UTF-8. r)r rrr)rdecodedr"r#rrrdecode_params_utf8Vr$r&z=&;:%+~,*@!()/?'$cCsT|rt|tksd}t|t|t|ft|rtdtj|dd}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&)queryerrorrrrr urldecodees  r1cCst|ttfrzt|}W|Styd}Y|Swt|drQzt|Wnty2d}Y|Sty=d}Y|Swtt|trH| n|}t |}|Sd}|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__) rrrr1r*hasattrdict TypeErrorlistitemsr&)rawrrrrextract_paramss.      r9cCstttdtS)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 @)rrgenerate_timestamprrrrgenerate_nonces r<cCstttS)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 )rinttimerrrrr;s r;cs$tdfddt|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. c3s|]}VqdSN)choice).0xcharsrandrr z!generate_token..)rjoinrangelengthrFrrErgenerate_tokensrNcCsTddl}tj}|j|tj|jdd}||j|||d}t |d}|S)Nr)seconds)scopeexpRS256UTF-8) jwtdatetimeutcnowrP timedelta expires_inupdateclaimsr to_unicode) private_pemrequestrTnowrZtokenrrrgenerate_signed_tokens   r`cCsddl}|j||dgdS)NrrR) algorithms)rTr) public_pemr_rTrrrverify_signed_tokensrccCs t||S)zGenerates an OAuth client_id OAuth 2 specify the format of client_id in https://tools.ietf.org/html/rfc6749#appendix-A. )rNrLrrrgenerate_client_ids rdcCs2t|tr |}tj|dd}||t|S)z)Extend a query with a list of two-tuples.Tr')rr4r7r-r.extendr)r/r queryparamsrrradd_params_to_qss  rgFc CsFt|\}}}}}}|rt||}nt||}t||||||fS)z5Add a list of two-tuples to the uri query components.)r-rg urlunparse) urirfragmentschnetpathparr/frarrradd_params_to_uris   rpcCsHt|t|kr dSd}t||D]\}}|t|t|AO}q|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)abresultrDyrrrsafe_string_equalss  rxrScst|tr|St|trt|dSt|drKzt|Wnty'Y|Sty8fdd|DYSwt|drB|}fdd|DS|S)z:Convert a number of different types of objects to unicode.encodingr2c3s|]}t|VqdSrAr[)rCiryrrrHrIzto_unicode..r7cs"i|] \}}t|t|qSrr{)rCr"r#ryrr $s"zto_unicode..)rrrr3r4r5r*r7)datarzrryrr[s"        r[csbeZdZdZiZddZddZfddZfdd Zdd d Z fd dZ fddZ Z S)CaseInsensitiveDictz3Basic case insensitive dict with strings only keys.cCs*dd|D|_|D]}||||<q dS)NcSsi|]}||qSr)lower)rCr"rrrr}0sz0CaseInsensitiveDict.__init__..)proxy)selfr~r"rrr__init__/szCaseInsensitiveDict.__init__cCs||jvSrA)rr)rr"rrr __contains__4sz CaseInsensitiveDict.__contains__cs*|j|}t||j|=dSrA)rrsuper __delitem__rr"key __class__rrr7s zCaseInsensitiveDict.__delitem__cs|j|}t|SrA)rrr __getitem__rrrrr<s zCaseInsensitiveDict.__getitem__NcCs||vr||S|SrAr)rr"defaultrrrget@szCaseInsensitiveDict.getcs t||||j|<dSrA)r __setitem__rr)rr"r#rrrrCszCaseInsensitiveDict.__setitem__cs8tj|i|t|i|D] }||j|<qdSrA)rrYr4rr)rargskwargsr"rrrrYGszCaseInsensitiveDict.updaterA) __name__ __module__ __qualname____doc__rrrrrrrrY __classcell__rrrrr)s    rc@sReZdZdZ  dddZddZd d Zed d Zed dZ eddZ 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. GETNrcsfdd}|||_|||_t||pi|_|||_t|j|_g|_i|_iddddddddddddd dd dd dd dd ddddddddddddddddddddddddddd |_ |j t t |j |j t |jpgdS)Ncsrt|S|SrAr{)rDryrr_sz"Request.__init__.. access_tokenclient client_id client_secretcodecode_challengecode_challenge_method code_verifierextra_credentials grant_type redirect_uri refresh_token request_token response_typerPscopesstate) r_usertoken_type_hint response_modenoncedisplaypromptrZmax_age ui_locales id_token_hint login_hint acr_values)ri http_methodrheadersbodyr9 decoded_body oauth_params validator_log_paramsrYr4r1 uri_query)rrirrrrzrrryrr\sv           "zRequest.__init__cCs||jvr |j|St|rA)rAttributeError)rnamerrr __getattr__s  zRequest.__getattr__cCsRtsdS|j}|j}|rtdt|}d|vrd|d<d|j|j ||S)Nzz  Authorizationz zF) rrrcopySANITIZE_PATTERNsubrformatrir)rrrrrr__repr__s  zRequest.__repr__cCst|jjSrA)r-rir/rrrrrszRequest.uri_querycCs|jsgStj|jdddS)NT)r(strict_parsing)rr-r.rrrruri_query_paramss  zRequest.uri_query_paramscCsPtt}dd|jp g|jD}|D] }||d7<qdd|DS)Ncss|]}|dVqdS)rNr)rCprrrrHsz+Request.duplicate_params..rcSsg|] \}}|dkr|qS)rr)rCr"crrr sz,Request.duplicate_params..) collections defaultdictr=rrr7)r seen_keysall_keysr"rrrduplicate_paramss zRequest.duplicate_params)rNNr) rrrrrrrpropertyrrrrrrrrMs  2  r)r )F)rS)3rrrUloggingrer> urllib.parseparser-rrrrrrr@rsecretsrr ImportErrorrandomr UNICODE_ASCII_CHARACTER_SETCLIENT_ID_CHARACTER_SETcompile IGNORECASErr+ always_safe getLoggerlogrr&r)rr1r9r<r;rNr`rcrdrgrprxr[r4rrrrrrsT             !    $