Class: Gitlab::LfsToken::HMACToken
- Inherits:
-
Object
- Object
- Gitlab::LfsToken::HMACToken
- Includes:
- LfsTokenHelper
- Defined in:
- lib/gitlab/lfs_token.rb
Instance Method Summary collapse
-
#initialize(actor) ⇒ HMACToken
constructor
A new instance of HMACToken.
- #token(expire_time) ⇒ Object
- #token_valid?(token_to_check) ⇒ Boolean
Methods included from LfsTokenHelper
Constructor Details
#initialize(actor) ⇒ HMACToken
Returns a new instance of HMACToken.
76 77 78 |
# File 'lib/gitlab/lfs_token.rb', line 76 def initialize(actor) @actor = actor end |
Instance Method Details
#token(expire_time) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/gitlab/lfs_token.rb', line 80 def token(expire_time) hmac_token = JSONWebToken::HMACToken.new(secret) hmac_token.expire_time = Time.now + expire_time hmac_token[:data] = { actor: actor_name } hmac_token.encoded end |
#token_valid?(token_to_check) ⇒ Boolean
87 88 89 90 91 92 |
# File 'lib/gitlab/lfs_token.rb', line 87 def token_valid?(token_to_check) decoded_token = JSONWebToken::HMACToken.decode(token_to_check, secret).first decoded_token.dig('data', 'actor') == actor_name rescue JWT::DecodeError false end |