Create a gist now

Instantly share code, notes, and snippets.

@nov /line_login.rb
Last active Sep 29, 2017

What would you like to do?
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