Class: PadlockAuth::Http::ForbiddenTokenResponse
- Inherits:
-
ErrorResponse
- Object
- ErrorResponse
- PadlockAuth::Http::ForbiddenTokenResponse
- Defined in:
- lib/padlock_auth/http/forbidden_token_response.rb
Overview
A response for a forbidden token.
A forbidden token response is returned when a token is valid, but does not have the required scopes.
Instance Attribute Summary collapse
-
#description ⇒ String
readonly
A translated description of the error.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
Attributes inherited from ErrorResponse
Class Method Summary collapse
-
.from_access_token(access_token, scopes, attributes = {}) ⇒ Object
Create a new forbidden token response from an access token.
Instance Method Summary collapse
-
#headers ⇒ Hash
HTTP headers.
-
#initialize(attributes = {}) ⇒ ForbiddenTokenResponse
constructor
Create a new forbidden token response.
Methods inherited from ErrorResponse
Constructor Details
#initialize(attributes = {}) ⇒ ForbiddenTokenResponse
Create a new forbidden token response.
31 32 33 34 35 |
# File 'lib/padlock_auth/http/forbidden_token_response.rb', line 31 def initialize(attributes = {}) super(attributes.merge(name: :invalid_scope, status: :forbidden)) @reason = attributes[:reason] || :unknown @scopes = attributes[:scopes] end |
Instance Attribute Details
#description ⇒ String (readonly)
Returns A translated description of the error.
40 41 42 43 44 45 46 47 48 |
# File 'lib/padlock_auth/http/forbidden_token_response.rb', line 40 def description @description ||= I18n.translate( @reason, scope: i[padlock_auth errors forbidden_token], oauth_scopes: @scopes.map(&:to_s).join(" "), default: :unknown ) end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
12 13 14 |
# File 'lib/padlock_auth/http/forbidden_token_response.rb', line 12 def reason @reason end |
Class Method Details
.from_access_token(access_token, scopes, attributes = {}) ⇒ Object
Create a new forbidden token response from an access token.
23 24 25 |
# File 'lib/padlock_auth/http/forbidden_token_response.rb', line 23 def self.from_access_token(access_token, scopes, attributes = {}) new(attributes.merge(reason: access_token&.forbidden_token_reason, scopes: scopes)) end |
Instance Method Details
#headers ⇒ Hash
Returns HTTP headers.
52 53 54 55 56 |
# File 'lib/padlock_auth/http/forbidden_token_response.rb', line 52 def headers headers = super headers.delete "WWW-Authenticate" # Authentication was successful, so no need to display auth error info headers end |