Class: Doorkeeper::OAuth::TokenIntrospection

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

Overview

RFC7662 OAuth 2.0 Token Introspection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, token) ⇒ TokenIntrospection

Returns a new instance of TokenIntrospection.



11
12
13
14
# File 'lib/doorkeeper/oauth/token_introspection.rb', line 11

def initialize(server, token)
  @server = server
  @token = token
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



9
10
11
# File 'lib/doorkeeper/oauth/token_introspection.rb', line 9

def error
  @error
end

#invalid_request_reasonObject (readonly)

Returns the value of attribute invalid_request_reason.



9
10
11
# File 'lib/doorkeeper/oauth/token_introspection.rb', line 9

def invalid_request_reason
  @invalid_request_reason
end

#tokenObject (readonly)

Returns the value of attribute token.



9
10
11
# File 'lib/doorkeeper/oauth/token_introspection.rb', line 9

def token
  @token
end

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/doorkeeper/oauth/token_introspection.rb', line 16

def authorized?
  authorize!
  @error.blank?
end

#error_responseObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/doorkeeper/oauth/token_introspection.rb', line 21

def error_response
  return if @error.blank?

  if @error == Errors::InvalidToken
    OAuth::InvalidTokenResponse.from_access_token(authorized_token)
  elsif @error == Errors::InvalidRequest
    OAuth::InvalidRequestResponse.from_request(self)
  else
    OAuth::ErrorResponse.from_request(self)
  end
end

#to_jsonObject



33
34
35
# File 'lib/doorkeeper/oauth/token_introspection.rb', line 33

def to_json(*)
  active? ? success_response : failure_response
end