Class: Sorcery::Providers::Heroku
- Includes:
- Sorcery::Protocols::Oauth2
- Defined in:
- lib/sorcery/providers/heroku.rb
Overview
NOTE: The full path must be set for OAuth Callback URL when configuring the API Client Information on Heroku.
Instance Attribute Summary collapse
-
#auth_path ⇒ Object
Returns the value of attribute auth_path.
-
#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
- #get_user_hash(access_token) ⇒ Object
-
#initialize ⇒ Heroku
constructor
A new instance of Heroku.
- #login_url(_params, _session) ⇒ Object
-
#process_callback(params, _session) ⇒ Object
tries to login the user from access token.
Methods included from Sorcery::Protocols::Oauth2
#authorize_url, #build_client, #get_access_token, #oauth_version
Methods inherited from Base
#auth_hash, descendants, #has_callback?, name
Constructor Details
#initialize ⇒ Heroku
Returns a new instance of Heroku.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sorcery/providers/heroku.rb', line 19 def initialize super @scope = nil @site = 'https://id.heroku.com' @user_info_path = 'https://api.heroku.com/account' @auth_path = '/oauth/authorize' @token_url = '/oauth/token' @user_info_path = '/account' @state = SecureRandom.hex(16) end |
Instance Attribute Details
#auth_path ⇒ Object
Returns the value of attribute auth_path.
17 18 19 |
# File 'lib/sorcery/providers/heroku.rb', line 17 def auth_path @auth_path end |
#scope ⇒ Object
Returns the value of attribute scope.
17 18 19 |
# File 'lib/sorcery/providers/heroku.rb', line 17 def scope @scope end |
#token_url ⇒ Object
Returns the value of attribute token_url.
17 18 19 |
# File 'lib/sorcery/providers/heroku.rb', line 17 def token_url @token_url end |
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
17 18 19 |
# File 'lib/sorcery/providers/heroku.rb', line 17 def user_info_path @user_info_path end |
Instance Method Details
#get_user_hash(access_token) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/sorcery/providers/heroku.rb', line 31 def get_user_hash(access_token) response = access_token.get(user_info_path) body = JSON.parse(response.body) auth_hash(access_token).tap do |h| h[:user_info] = body h[:uid] = body['id'].to_s h[:email] = body['email'].to_s end end |
#login_url(_params, _session) ⇒ Object
41 42 43 |
# File 'lib/sorcery/providers/heroku.rb', line 41 def login_url(_params, _session) (authorize_url: auth_path) end |
#process_callback(params, _session) ⇒ Object
tries to login the user from access token
46 47 48 49 50 51 52 53 |
# File 'lib/sorcery/providers/heroku.rb', line 46 def process_callback(params, _session) raise 'Invalid state. Potential Cross Site Forgery' if params[:state] != state args = {}.tap do |a| a[:code] = params[:code] if params[:code] end get_access_token(args, token_url: token_url, token_method: :post) end |