Last active
November 24, 2017 10:07
-
-
Save nov/58912dda45a65768d8f05343225780b2 to your computer and use it in GitHub Desktop.
LINE ID Login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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