Skip to content

Instantly share code, notes, and snippets.

@nov
Created April 17, 2016 10:36
  • 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
Save nov/3f284aa8cec5ed6bc332e9a5c9d93851 to your computer and use it in GitHub Desktop.
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