Class: Sorcery::Providers::Heroku

Inherits:
Base
  • Object
show all
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

Attributes inherited from Base

#access_token, #callback_url, #key, #original_callback_url, #secret, #site, #state, #user_info_mapping

Instance Method Summary collapse

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

#initializeHeroku

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_pathObject

Returns the value of attribute auth_path.



17
18
19
# File 'lib/sorcery/providers/heroku.rb', line 17

def auth_path
  @auth_path
end

#scopeObject

Returns the value of attribute scope.



17
18
19
# File 'lib/sorcery/providers/heroku.rb', line 17

def scope
  @scope
end

#token_urlObject

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_pathObject

Returns the value of attribute user_info_path.



17
18
19
# File 'lib/sorcery/providers/heroku.rb', line 17

def 
  @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()
  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 (_params, _session)
  authorize_url(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