Class: PadlockAuth::Http::InvalidTokenResponse

Inherits:
ErrorResponse show all
Defined in:
lib/padlock_auth/http/invalid_token_response.rb

Overview

A response for an invalid token.

An invalid token response is returned when a token is invalid.

Instance Attribute Summary collapse

Attributes inherited from ErrorResponse

#name, #status

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ErrorResponse

#body, #headers, #raise_exception!

Constructor Details

#initialize(attributes = {}) ⇒ InvalidTokenResponse

Create a new invalid token response.

Parameters:

  • attributes (Hash) (defaults to: {})

    Attributes



35
36
37
38
# File 'lib/padlock_auth/http/invalid_token_response.rb', line 35

def initialize(attributes = {})
  super(attributes.merge(name: :invalid_grant, status: :unauthorized))
  @reason = attributes[:reason] || :unknown
end

Instance Attribute Details

#descriptionString (readonly)

Returns A translated description of the error.

Returns:

  • (String)

    A translated description of the error



43
44
45
46
47
48
49
50
# File 'lib/padlock_auth/http/invalid_token_response.rb', line 43

def description
  @description ||=
    I18n.translate(
      reason,
      scope: i[padlock_auth errors messages invalid_token],
      default: :unknown
    )
end

#reasonSymbol (readonly)

Reason for the invalid token.

Possible reasons are:

  • :revoked

  • :expired

  • :unknown

Returns:

  • (Symbol)

    The reason for the invalid token



19
20
21
# File 'lib/padlock_auth/http/invalid_token_response.rb', line 19

def reason
  @reason
end

Class Method Details

.from_access_token(access_token, attributes = {}) ⇒ Object

Create a new invalid token response from an access token.

Parameters:



27
28
29
# File 'lib/padlock_auth/http/invalid_token_response.rb', line 27

def self.from_access_token(access_token, attributes = {})
  new(attributes.merge(reason: access_token&.invalid_token_reason))
end