Class: Apill::Tokens::RequestAuthorization
- Inherits:
-
Object
- Object
- Apill::Tokens::RequestAuthorization
- Defined in:
- lib/apill/tokens/request_authorization.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#initialize(token:) ⇒ RequestAuthorization
constructor
A new instance of RequestAuthorization.
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(token:) ⇒ RequestAuthorization
Returns a new instance of RequestAuthorization.
11 12 13 |
# File 'lib/apill/tokens/request_authorization.rb', line 11 def initialize(token:) self.token = token end |
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
9 10 11 |
# File 'lib/apill/tokens/request_authorization.rb', line 9 def token @token end |
Class Method Details
.convert(raw_token:, token_private_key: Apill.configuration.token_private_key) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/apill/tokens/request_authorization.rb', line 27 def self.convert(raw_token:, token_private_key: Apill.configuration.token_private_key) return NullRequestAuthorization.instance if raw_token.to_s == '' decrypted_token = JSON::JWT.decode(raw_token, token_private_key).plain_text decoded_token = JWT.decode(decrypted_token, token_private_key, true, algorithm: 'RS256', verify_expiration: true, verify_not_before: true, verify_iat: true, leeway: 5, ) new(token: decoded_token) rescue JSON::JWT::Exception, JSON::JWT::InvalidFormat, JSON::JWT::VerificationFailed, JSON::JWT::UnexpectedAlgorithm, JWT::DecodeError, JWT::VerificationError, JWT::ExpiredSignature, JWT::IncorrectAlgorithm, JWT::ImmatureSignature, JWT::InvalidIssuerError, JWT::InvalidIatError, JWT::InvalidAudError, JWT::InvalidSubError, JWT::InvalidJtiError, OpenSSL::PKey::RSAError InvalidRequestAuthorization.instance end |
Instance Method Details
#blank? ⇒ Boolean
19 20 21 |
# File 'lib/apill/tokens/request_authorization.rb', line 19 def blank? false end |
#to_h ⇒ Object
23 24 25 |
# File 'lib/apill/tokens/request_authorization.rb', line 23 def to_h token end |
#valid? ⇒ Boolean
15 16 17 |
# File 'lib/apill/tokens/request_authorization.rb', line 15 def valid? true end |