Created
June 26, 2019 22:10
-
-
Save bobisme/a53a5713c5bd101befc4177259700f7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'base64' | |
require 'openssl' | |
require 'securerandom' | |
require 'uri' | |
BASE_URL = ENV['OAUTH2_BASE_URL'] | |
REDIRECT_URI = ENV['REDIRECT_URI'] | |
CLIENT_ID = ENV['OAUTH2_CLIENT_ID'] | |
code_verifier = Base64.urlsafe_encode64(SecureRandom.bytes(128), padding: false) | |
code_challenge = Base64.urlsafe_encode64( | |
OpenSSL::Digest::SHA256.digest(code_verifier), | |
padding: false, | |
) | |
state = SecureRandom.uuid | |
params = { | |
client_id: CLIENT_ID, | |
response_type: 'code', | |
scope: 'openid', | |
redirect_uri: REDIRECT_URI, | |
state: state, | |
code_challenge_method: 'S256', | |
code_challenge: code_challenge, | |
} | |
param_string = params.map { |k, v| "#{k.to_s}=#{URI.encode_www_form_component(v)}" }.join('&') | |
puts "#{BASE_URL}/authorize?#{param_string}" | |
puts code_verifier |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment