Class: Doorkeeper::OAuth::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/doorkeeper/oauth/token.rb

Class Method Summary collapse

Class Method Details

.authenticate(request, *methods) ⇒ Object


15
16
17
18
19
20
21
22
23
# File 'lib/doorkeeper/oauth/token.rb', line 15

def authenticate(request, *methods)
  if (token = from_request(request, *methods))
    access_token = Doorkeeper.config.access_token_model.by_token(token)
    if access_token.present? && Doorkeeper.config.refresh_token_enabled?
      access_token.revoke_previous_refresh_token!
    end
    access_token
  end
end

.from_access_token_param(request) ⇒ Object


25
26
27
# File 'lib/doorkeeper/oauth/token.rb', line 25

def from_access_token_param(request)
  request.parameters[:access_token]
end

.from_basic_authorization(request) ⇒ Object


39
40
41
42
43
# File 'lib/doorkeeper/oauth/token.rb', line 39

def from_basic_authorization(request)
  pattern = /^Basic /i
  header = request.authorization
  token_from_basic_header(header, pattern) if match?(header, pattern)
end

.from_bearer_authorization(request) ⇒ Object


33
34
35
36
37
# File 'lib/doorkeeper/oauth/token.rb', line 33

def from_bearer_authorization(request)
  pattern = /^Bearer /i
  header = request.authorization
  token_from_header(header, pattern) if match?(header, pattern)
end

.from_bearer_param(request) ⇒ Object


29
30
31
# File 'lib/doorkeeper/oauth/token.rb', line 29

def from_bearer_param(request)
  request.parameters[:bearer_token]
end

.from_request(request, *methods) ⇒ Object


7
8
9
10
11
12
13
# File 'lib/doorkeeper/oauth/token.rb', line 7

def from_request(request, *methods)
  methods.inject(nil) do |_, method|
    method = self.method(method) if method.is_a?(Symbol)
    credentials = method.call(request)
    break credentials if credentials.present?
  end
end