Class: Himari::AccessToken
- Inherits:
-
Object
- Object
- Himari::AccessToken
- Includes:
- TokenString
- Defined in:
- lib/himari/access_token.rb
Defined Under Namespace
Classes: Bearer
Instance Attribute Summary collapse
-
#claims ⇒ Object
readonly
Returns the value of attribute claims.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#expiry ⇒ Object
readonly
Returns the value of attribute expiry.
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #as_log ⇒ Object
-
#initialize(handle:, client_id:, claims:, expiry:, secret: nil, secret_hash: nil) ⇒ AccessToken
constructor
A new instance of AccessToken.
- #to_bearer ⇒ Object
- #userinfo ⇒ Object
Methods included from TokenString
#format, included, #magic_header, #secret, #secret_hash, #verify!, #verify_expiry!, #verify_secret!
Constructor Details
#initialize(handle:, client_id:, claims:, expiry:, secret: nil, secret_hash: nil) ⇒ AccessToken
Returns a new instance of AccessToken.
35 36 37 38 39 40 41 42 43 |
# File 'lib/himari/access_token.rb', line 35 def initialize(handle:, client_id:, claims:, expiry:, secret: nil, secret_hash: nil) @handle = handle @client_id = client_id @claims = claims @expiry = expiry @secret = secret @secret_hash = secret_hash end |
Instance Attribute Details
#claims ⇒ Object (readonly)
Returns the value of attribute claims.
45 46 47 |
# File 'lib/himari/access_token.rb', line 45 def claims @claims end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
45 46 47 |
# File 'lib/himari/access_token.rb', line 45 def client_id @client_id end |
#expiry ⇒ Object (readonly)
Returns the value of attribute expiry.
45 46 47 |
# File 'lib/himari/access_token.rb', line 45 def expiry @expiry end |
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
45 46 47 |
# File 'lib/himari/access_token.rb', line 45 def handle @handle end |
Class Method Details
.default_lifetime ⇒ Object
22 23 24 |
# File 'lib/himari/access_token.rb', line 22 def self.default_lifetime 3600 end |
.from_authz(authz) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/himari/access_token.rb', line 27 def self.from_authz(authz) make( client_id: authz.client_id, claims: authz.claims, lifetime: authz.lifetime.access_token, ) end |
.magic_header ⇒ Object
18 19 20 |
# File 'lib/himari/access_token.rb', line 18 def self.magic_header 'hmat' end |
Instance Method Details
#as_json ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/himari/access_token.rb', line 69 def as_json { handle: handle, secret_hash: secret_hash, client_id: client_id, claims: claims, expiry: expiry.to_i, } end |
#as_log ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/himari/access_token.rb', line 60 def as_log { handle: handle, client_id: client_id, claims: claims, expiry: expiry, } end |
#to_bearer ⇒ Object
53 54 55 56 57 58 |
# File 'lib/himari/access_token.rb', line 53 def to_bearer Bearer.new( access_token: format.to_s, expires_in: (expiry - Time.now.to_i).to_i, ) end |
#userinfo ⇒ Object
47 48 49 50 51 |
# File 'lib/himari/access_token.rb', line 47 def userinfo claims.merge( aud: client_id, ) end |