diff --git a/README.md b/README.md index fb2c3eb..86cddde 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,8 @@ get('/authorize') do user_id = request.session['user_id'] # User needs to take care of generating the code_verifier and storing it in # the session. - request.session['code_verifier'] ||= authorizer.generate_code_verifier + request.session['code_verifier'] ||= Google::Auth::WebUserAuthorizer.generate_code_verifier + authorizer.code_verifier = request.session['code_verifier'] credentials = authorizer.get_credentials(user_id, request) if credentials.nil? redirect authorizer.get_authorization_url(login_hint: user_id, request: request) diff --git a/lib/googleauth/user_authorizer.rb b/lib/googleauth/user_authorizer.rb index afc21be..e6948d5 100644 --- a/lib/googleauth/user_authorizer.rb +++ b/lib/googleauth/user_authorizer.rb @@ -260,11 +260,9 @@ def code_verifier= new_code_verifier # Generate the code verifier needed to be sent while fetching # authorization URL. - def code_verifier - @code_verifier ||= begin - random_number = rand 32..96 - SecureRandom.alphanumeric random_number - end + def self.generate_code_verifier + random_number = rand 32..96 + SecureRandom.alphanumeric random_number end private diff --git a/spec/googleauth/web_user_authorizer_spec.rb b/spec/googleauth/web_user_authorizer_spec.rb index 2e07d9c..edcb14d 100644 --- a/spec/googleauth/web_user_authorizer_spec.rb +++ b/spec/googleauth/web_user_authorizer_spec.rb @@ -90,7 +90,7 @@ end it "should include code_challenge and code_challenge_method" do - authorizer.generate_code_verifier + authorizer.code_verifier = Google::Auth::WebUserAuthorizer.generate_code_verifier url = authorizer.get_authorization_url(request: request) expect(url).to match(/code_challenge=/) expect(url).to match(/code_challenge_method=S256/)