Exception: KeycloakApiRails::TokenError
- Inherits:
-
StandardError
- Object
- StandardError
- KeycloakApiRails::TokenError
- Defined in:
- lib/keycloak-api-rails/token_error.rb
Instance Attribute Summary collapse
-
#original_error ⇒ Object
readonly
Returns the value of attribute original_error.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
- .expired(token) ⇒ Object
- .invalid_audience(token) ⇒ Object
- .invalid_claim(token, claim) ⇒ Object
- .invalid_format(token, original_error = nil) ⇒ Object
- .invalid_realm(token) ⇒ Object
- .invalid_token_type(token) ⇒ Object
- .missing_claim(token, claim) ⇒ Object
- .no_token(token) ⇒ Object
- .not_yet_valid(token) ⇒ Object
- .unknown(token, original_error) ⇒ Object
- .verification_failed(token, original_error) ⇒ Object
Instance Method Summary collapse
-
#challenge ⇒ Object
RFC 6750: a request that carried no credentials at all gets the bare challenge, no error code.
-
#initialize(token, reason, message, original_error = nil) ⇒ TokenError
constructor
A new instance of TokenError.
Constructor Details
#initialize(token, reason, message, original_error = nil) ⇒ TokenError
Returns a new instance of TokenError.
7 8 9 10 11 12 |
# File 'lib/keycloak-api-rails/token_error.rb', line 7 def initialize(token, reason, , original_error = nil) super() @token = token @reason = reason @original_error = original_error end |
Instance Attribute Details
#original_error ⇒ Object (readonly)
Returns the value of attribute original_error.
5 6 7 |
# File 'lib/keycloak-api-rails/token_error.rb', line 5 def original_error @original_error end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
5 6 7 |
# File 'lib/keycloak-api-rails/token_error.rb', line 5 def reason @reason end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
5 6 7 |
# File 'lib/keycloak-api-rails/token_error.rb', line 5 def token @token end |
Class Method Details
.expired(token) ⇒ Object
39 40 41 |
# File 'lib/keycloak-api-rails/token_error.rb', line 39 def self.expired(token) new(token, :expired, "JWT token is expired") end |
.invalid_audience(token) ⇒ Object
47 48 49 |
# File 'lib/keycloak-api-rails/token_error.rb', line 47 def self.invalid_audience(token) new(token, :invalid_audience, "JWT token has been issued for another audience") end |
.invalid_claim(token, claim) ⇒ Object
59 60 61 |
# File 'lib/keycloak-api-rails/token_error.rb', line 59 def self.invalid_claim(token, claim) new(token, :invalid_claim, "JWT token carries an invalid '#{claim}' claim: it must be a number of seconds since the Epoch") end |
.invalid_format(token, original_error = nil) ⇒ Object
27 28 29 |
# File 'lib/keycloak-api-rails/token_error.rb', line 27 def self.invalid_format(token, original_error = nil) new(token, :invalid_format, "Wrong JWT Format", original_error) end |
.invalid_realm(token) ⇒ Object
31 32 33 |
# File 'lib/keycloak-api-rails/token_error.rb', line 31 def self.invalid_realm(token) new(token, :invalid_realm, "JWT token does not have a valid realm") end |
.invalid_token_type(token) ⇒ Object
51 52 53 |
# File 'lib/keycloak-api-rails/token_error.rb', line 51 def self.invalid_token_type(token) new(token, :invalid_token_type, "JWT token is not of the expected type") end |
.missing_claim(token, claim) ⇒ Object
55 56 57 |
# File 'lib/keycloak-api-rails/token_error.rb', line 55 def self.missing_claim(token, claim) new(token, :missing_claim, "JWT token does not carry the mandatory claim '#{claim}'") end |
.no_token(token) ⇒ Object
35 36 37 |
# File 'lib/keycloak-api-rails/token_error.rb', line 35 def self.no_token(token) new(token, :no_token, "No JWT token provided") end |
.not_yet_valid(token) ⇒ Object
43 44 45 |
# File 'lib/keycloak-api-rails/token_error.rb', line 43 def self.not_yet_valid(token) new(token, :not_yet_valid, "JWT token is not valid yet") end |
.unknown(token, original_error) ⇒ Object
63 64 65 |
# File 'lib/keycloak-api-rails/token_error.rb', line 63 def self.unknown(token, original_error) new(token, :unknown, "Failed to read JWT token", original_error) end |
.verification_failed(token, original_error) ⇒ Object
23 24 25 |
# File 'lib/keycloak-api-rails/token_error.rb', line 23 def self.verification_failed(token, original_error) new(token, :verification_failed, "Failed to verify JWT token", original_error) end |
Instance Method Details
#challenge ⇒ Object
RFC 6750: a request that carried no credentials at all gets the bare challenge, no error code.
15 16 17 18 19 20 21 |
# File 'lib/keycloak-api-rails/token_error.rb', line 15 def challenge if reason == :no_token "Bearer" else %(Bearer error="invalid_token", error_description="#{.gsub(/["\\]/, '')}") end end |