Class: Toolchest::Auth::OAuth

Inherits:
Base
  • Object
show all
Defined in:
lib/toolchest/auth/oauth.rb

Instance Method Summary collapse

Constructor Details

#initialize(mount_key = :default) ⇒ OAuth

Returns a new instance of OAuth.



4
5
6
# File 'lib/toolchest/auth/oauth.rb', line 4

def initialize(mount_key = :default)
  @mount_key = mount_key.to_s
end

Instance Method Details

#authenticate(request) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/toolchest/auth/oauth.rb', line 8

def authenticate(request)
  token_string = extract_bearer_token(request)
  return nil unless token_string

  token = Toolchest::OauthAccessToken.find_by_token(token_string, mount_key: @mount_key)
  return nil unless token

  config = Toolchest.configuration(@mount_key.to_sym)
  owner = if config.send(:instance_variable_get, :@authenticate_block)
    config.authenticate_with(token)
  end

  AuthContext.new(
    resource_owner: owner,
    scopes: token.scopes_array,
    token: token
  )
end