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
@@ -275,7 +275,7 @@ def _scope_set(scope):
275275def _generate_pkce_code_verifier (length = 43 ):
276276 assert 43 <= length <= 128
277277 verifier = "" .join ( # https://tools.ietf.org/html/rfc7636#section-4.1
278- random . sample (string .ascii_letters + string .digits + "-._~" , length ))
278+ secrets . choice (string .ascii_letters + string .digits + "-._~" ) for _ in range ( length ))
279279 code_challenge = (
280280 # https://tools.ietf.org/html/rfc7636#section-4.2
281281 base64 .urlsafe_b64encode (hashlib .sha256 (verifier .encode ("ascii" )).digest ())
@@ -473,7 +473,7 @@ def initiate_auth_code_flow(
473473 raise ValueError ('response_type="token ..." is not allowed' )
474474 pkce = _generate_pkce_code_verifier ()
475475 flow = { # These data are required by obtain_token_by_auth_code_flow()
476- "state" : state or "" .join (random . sample (string .ascii_letters , 16 )),
476+ "state" : state or "" .join (secrets . choice (string .ascii_letters ) for _ in range ( 16 )),
477477 "redirect_uri" : redirect_uri ,
478478 "scope" : scope ,
479479 }
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