class Sorcery::Providers::Heroku

NOTE: The full path must be set for OAuth Callback URL when configuring the API Client Information on Heroku.

Attributes

auth_path[RW]
scope[RW]
token_url[RW]
user_info_path[RW]

Public Class Methods

new() click to toggle source
Calls superclass method Sorcery::Providers::Base::new
# 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

Public Instance Methods

get_user_hash(access_token) click to toggle source
# 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) click to toggle source
# File lib/sorcery/providers/heroku.rb, line 41
def login_url(_params, _session)
  authorize_url(authorize_url: auth_path)
end
process_callback(params, _session) click to toggle source

tries to login the user from access token

# 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