Skip to content

Instantly share code, notes, and snippets.

Last active May 19, 2020 10:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
require 'rack/oauth2'
client =
identifier: 'YOUR_CLIENT_ID',
redirect_uri: 'YOUR_REDIRECT_URI',
authorization_endpoint: '',
token_endpoint: ''
code_verifier = SecureRandom.hex(32)
code_challenge = Base64.urlsafe_encode64(OpenSSL::Digest::SHA256.digest(code_verifier), padding: false)
authorization_url = client.authorization_uri(
scope: 'email',
# code_challenge: code_challenge,
# code_challenge_method: :S256
puts authorization_url
`open "#{authorization_url}"`
print 'code: ' and STDOUT.flush
code = gets.chop
client.authorization_code = code
code_verifier: code_verifier
# NOTE: if code_challange isn't sent at AuthZ Req, you should get an error as below.
# Status: 400 Bad Request
# {
# "error": "invalid_grant",
# "error_description": "code_verifier or verifier is not needed."
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment