Class: Sorcery::Providers::Line
- Includes:
- Sorcery::Protocols::Oauth2
- Defined in:
- lib/sorcery/providers/line.rb
Overview
This class adds support for OAuth with line.com.
config.line.key = <key>
config.line.secret = <secret>
...
Instance Attribute Summary collapse
-
#auth_path ⇒ Object
Returns the value of attribute auth_path.
-
#bot_prompt ⇒ Object
Returns the value of attribute bot_prompt.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#token_url ⇒ Object
Returns the value of attribute token_url.
-
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
Attributes inherited from Base
#access_token, #callback_url, #key, #original_callback_url, #secret, #site, #state, #user_info_mapping
Instance Method Summary collapse
-
#authorize_url(options = {}) ⇒ Object
overrides oauth2#authorize_url to add bot_prompt query.
- #get_user_hash(access_token) ⇒ Object
-
#initialize ⇒ Line
constructor
A new instance of Line.
-
#login_url(_params, _session) ⇒ Object
calculates and returns the url to which the user should be redirected, to get authenticated at the external provider’s site.
-
#process_callback(params, _session) ⇒ Object
tries to login the user from access token.
Methods included from Sorcery::Protocols::Oauth2
#build_client, #get_access_token, #oauth_version
Methods inherited from Base
#auth_hash, descendants, #has_callback?, name
Constructor Details
#initialize ⇒ Line
Returns a new instance of Line.
14 15 16 17 18 19 20 21 22 |
# File 'lib/sorcery/providers/line.rb', line 14 def initialize super @site = 'https://access.line.me' @user_info_path = 'https://api.line.me/v2/profile' @token_url = 'https://api.line.me/oauth2/v2.1/token' @auth_path = 'oauth2/v2.1/authorize' @scope = 'profile' end |
Instance Attribute Details
#auth_path ⇒ Object
Returns the value of attribute auth_path.
12 13 14 |
# File 'lib/sorcery/providers/line.rb', line 12 def auth_path @auth_path end |
#bot_prompt ⇒ Object
Returns the value of attribute bot_prompt.
12 13 14 |
# File 'lib/sorcery/providers/line.rb', line 12 def bot_prompt @bot_prompt end |
#scope ⇒ Object
Returns the value of attribute scope.
12 13 14 |
# File 'lib/sorcery/providers/line.rb', line 12 def scope @scope end |
#token_url ⇒ Object
Returns the value of attribute token_url.
12 13 14 |
# File 'lib/sorcery/providers/line.rb', line 12 def token_url @token_url end |
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
12 13 14 |
# File 'lib/sorcery/providers/line.rb', line 12 def user_info_path @user_info_path end |
Instance Method Details
#authorize_url(options = {}) ⇒ Object
overrides oauth2#authorize_url to add bot_prompt query.
40 41 42 43 44 45 46 |
# File 'lib/sorcery/providers/line.rb', line 40 def ( = {}) .merge!({ connection_opts: { params: { bot_prompt: bot_prompt } } }) if bot_prompt.present? super() end |
#get_user_hash(access_token) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/sorcery/providers/line.rb', line 24 def get_user_hash(access_token) response = access_token.get(user_info_path) auth_hash(access_token).tap do |h| h[:user_info] = JSON.parse(response.body) h[:uid] = h[:user_info]['userId'].to_s end end |
#login_url(_params, _session) ⇒ Object
calculates and returns the url to which the user should be redirected, to get authenticated at the external provider’s site.
34 35 36 37 |
# File 'lib/sorcery/providers/line.rb', line 34 def login_url(_params, _session) @state = SecureRandom.hex(16) (authorize_url: auth_path) end |
#process_callback(params, _session) ⇒ Object
tries to login the user from access token
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sorcery/providers/line.rb', line 49 def process_callback(params, _session) args = {}.tap do |a| a[:code] = params[:code] if params[:code] end get_access_token( args, token_url: token_url, token_method: :post, grant_type: 'authorization_code' ) end |