Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
require 'openid_connect'
OpenIDConnect.debug!
config = OpenIDConnect::Discovery::Provider::Config.discover! 'https://sts.example.com/adfs'
client = OpenIDConnect::Client.new(
identifier: '2940bc16-983c-41ca-b373-4c6045278627', # Native App's client_id
redirect_uri: 'custom-schema://foobar',
authorization_endpoint: config.authorization_endpoint,
token_endpoint: config.token_endpoint,
userinfo_endpoint: config.userinfo_endpoint
)
authorization_uri = client.authorization_uri(
scope: [:openid, :email, :profile]
)
puts authorization_uri
`open "#{authorization_uri}"`
code = gets.chop!
client.authorization_code = code
token = client.access_token! # aud = urn:microsoft:userinfo
token.userinfo!
client.refresh_token = token.refresh_token
token2 = client.access_token!(
resource: 'http://backend.dev' # Native App Backend's identifier
) # aud = http://backend.dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment