Skip to content

Instantly share code, notes, and snippets.

@nov
Last active November 24, 2017 10:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nov/58912dda45a65768d8f05343225780b2 to your computer and use it in GitHub Desktop.
Save nov/58912dda45a65768d8f05343225780b2 to your computer and use it in GitHub Desktop.
LINE ID Login
require 'openid_connect'
OpenIDConnect.debug!
config = {
client_id: 'YOUR-CHANNEL-ID',
client_secret: 'YOUR-CHANNEL-SECRET'
}
client = OpenIDConnect::Client.new(
identifier: config[:client_id],
secret: config[:client_secret],
authorization_endpoint: 'https://access.line.me/oauth2/v2.1/authorize',
token_endpoint: 'https://api.line.me/oauth2/v2.1/token',
# 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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment