Skip to content

Instantly share code, notes, and snippets.

Last active Nov 24, 2017
What would you like to do?
require 'openid_connect'
config = {
client_id: 'YOUR-CHANNEL-ID',
client_secret: 'YOUR-CHANNEL-SECRET'
client =
identifier: config[:client_id],
secret: config[:client_secret],
authorization_endpoint: '',
token_endpoint: '',
# userinfo_endpoint: '', # NOTE: not yet implemented.
redirect_uri: 'http://localhost:3000/callback'
authorization_uri = client.authorization_uri(
scope: [:email, :profile], # NOTE: 'profile' is required, 'email' isn't supported for normal developers.
state: SecureRandom.hex(8), # NOTE: 'state' is required.
prompt: :none, # NOTE: 'none' is ignored.
bot_prompt: :normal # NOTE: not working? only for limited developers?
puts authorization_uri
`open "#{authorization_uri}"`
print 'code: ' and STDOUT.flush
code = gets.chop
client.authorization_code = code
token_response = client.access_token! :body # NOTE: Basic Auth header isn't supported.
id_token = token_response.id_token
puts JSON.pretty_generate(
JSON::JWT.decode id_token, config[:client_secret]
print 'refresh? (y/n): ' and STDOUT.flush
do_refresh = gets.chop
if do_refresh == 'y'
client.refresh_token = token_response.refresh_token
client.access_token! :body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment