File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313import base64
1414import sys
1515import functools
16- import random
16+ import secrets
1717import string
1818import hashlib
1919
@@ -278,7 +278,7 @@ def _scope_set(scope):
278278def _generate_pkce_code_verifier (length = 43 ):
279279 assert 43 <= length <= 128
280280 verifier = "" .join ( # https://tools.ietf.org/html/rfc7636#section-4.1
281- random . sample (string .ascii_letters + string .digits + "-._~" , length ))
281+ secrets . choice (string .ascii_letters + string .digits + "-._~" ) for _ in range ( length ))
282282 code_challenge = (
283283 # https://tools.ietf.org/html/rfc7636#section-4.2
284284 base64 .urlsafe_b64encode (hashlib .sha256 (verifier .encode ("ascii" )).digest ())
@@ -488,7 +488,7 @@ def initiate_auth_code_flow(
488488 raise ValueError ('response_type="token ..." is not allowed' )
489489 pkce = _generate_pkce_code_verifier ()
490490 flow = { # These data are required by obtain_token_by_auth_code_flow()
491- "state" : state or "" .join (random . sample (string .ascii_letters , 16 )),
491+ "state" : state or "" .join (secrets . choice (string .ascii_letters ) for _ in range ( 16 )),
492492 "redirect_uri" : redirect_uri ,
493493 "scope" : scope ,
494494 }
Original file line number Diff line number Diff line change 11import json
22import base64
33import time
4- import random
4+ import secrets
55import string
66import warnings
77import hashlib
@@ -238,7 +238,7 @@ def initiate_auth_code_flow(
238238 # Here we just automatically add it. If the caller do not want id_token,
239239 # they should simply go with oauth2.Client.
240240 _scope .append ("openid" )
241- nonce = "" .join (random . sample (string .ascii_letters , 16 ))
241+ nonce = "" .join (secrets . choice (string .ascii_letters ) for _ in range ( 16 ))
242242 flow = super (Client , self ).initiate_auth_code_flow (
243243 scope = _scope , nonce = _nonce_hash (nonce ), ** kwargs )
244244 flow ["nonce" ] = nonce
You can’t perform that action at this time.
0 commit comments