class Sorcery::Providers::Hh

This class adds support for OAuth with hh.ru.

config.hh.key = <key>
config.hh.secret = <secret>
...

Attributes

auth_path[RW]
response_type[RW]
scope[RW]
token_path[RW]
user_info_url[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/sorcery/providers/hh.rb, line 16
def initialize
  super

  @scope          = nil
  @site           = 'https://hh.ru/'
  @user_info_url  = 'http://api.hh.ru/me'
  @auth_path      = '/oauth/authorize'
  @token_path     = '/oauth/token'
  @grant_type     = 'authorization_code'
end

Public Instance Methods

get_user_hash(access_token) click to toggle source
# File lib/sorcery/providers/hh.rb, line 27
def get_user_hash(access_token)
  user_hash = auth_hash(access_token)

  headers = { authorization: "Bearer #{access_token.token}" }
  response = access_token.get(user_info_url, headers: headers)

  user_hash[:uid] = user_hash[:user_info]["id"] if user_hash[:user_info] = JSON.parse(response.body)

  user_hash
end
login_url(params, session) click to toggle source
# File lib/sorcery/providers/hh.rb, line 38
def login_url(params, session)
  authorize_url({ authorize_url: auth_path })
end
process_callback(params, session) click to toggle source
# File lib/sorcery/providers/hh.rb, line 42
def process_callback(params, session)
  args = {}.tap do |a|
    a[:code] = params[:code] if params[:code]
  end

  get_access_token(args, token_url: token_path, token_method: :post)
end