class Doorkeeper::OAuth::InvalidTokenResponse

Attributes

reason[R]

Public Class Methods

from_access_token(access_token, attributes = {}) click to toggle source
# File lib/doorkeeper/oauth/invalid_token_response.rb, line 8
def self.from_access_token(access_token, attributes = {})
  reason = if access_token&.revoked?
             :revoked
           elsif access_token&.expired?
             :expired
           else
             :unknown
           end

  new(attributes.merge(reason: reason))
end
new(attributes = {}) click to toggle source
Calls superclass method Doorkeeper::OAuth::ErrorResponse::new
# File lib/doorkeeper/oauth/invalid_token_response.rb, line 20
def initialize(attributes = {})
  super(attributes.merge(name: :invalid_token, state: :unauthorized))
  @reason = attributes[:reason] || :unknown
end

Public Instance Methods

description() click to toggle source
# File lib/doorkeeper/oauth/invalid_token_response.rb, line 29
def description
  @description ||=
    I18n.translate(
      @reason,
      scope: %i[doorkeeper errors messages invalid_token],
    )
end
status() click to toggle source
# File lib/doorkeeper/oauth/invalid_token_response.rb, line 25
def status
  :unauthorized
end

Protected Instance Methods

exception_class() click to toggle source
# File lib/doorkeeper/oauth/invalid_token_response.rb, line 39
def exception_class
  errors_mapping.fetch(reason)
end

Private Instance Methods

errors_mapping() click to toggle source
# File lib/doorkeeper/oauth/invalid_token_response.rb, line 45
def errors_mapping
  {
    expired: Doorkeeper::Errors::TokenExpired,
    revoked: Doorkeeper::Errors::TokenRevoked,
    unknown: Doorkeeper::Errors::TokenUnknown,
  }
end