Skip to content

Commit

Permalink
Make generate_code_verifier a class method
Browse files Browse the repository at this point in the history
  • Loading branch information
bajajneha27 committed Feb 8, 2024
1 parent 47c421d commit 6cdcd21
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions lib/googleauth/user_authorizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/googleauth/web_user_authorizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down

0 comments on commit 6cdcd21

Please sign in to comment.