class Secretkeeper::AccessToken
Attributes
access_token[R]
r_token[R]
token_expires_in[R]
Public Class Methods
generate()
click to toggle source
# File lib/secretkeeper/access_token.rb, line 39 def self.generate SecureRandom.hex(32) end
new(attributes = {})
click to toggle source
Calls superclass method
# File lib/secretkeeper/access_token.rb, line 9 def initialize(attributes = {}) loop do @access_token = AccessToken.generate @r_token = AccessToken.generate break unless token_exists? end @token_expires_in = Secretkeeper.configuration.access_token_expires_in super((attributes || {}).merge(token_params)) end
Public Instance Methods
accessible?()
click to toggle source
# File lib/secretkeeper/access_token.rb, line 23 def accessible? !revoked? && !expired? end
expired?()
click to toggle source
# File lib/secretkeeper/access_token.rb, line 31 def expired? created_at + expires_in.seconds <= Time.zone.now end
refreshable?()
click to toggle source
# File lib/secretkeeper/access_token.rb, line 35 def refreshable? !revoked? end
revoke!()
click to toggle source
# File lib/secretkeeper/access_token.rb, line 19 def revoke! revoked_at.nil? && update(revoked_at: Time.zone.now) end
revoked?()
click to toggle source
# File lib/secretkeeper/access_token.rb, line 27 def revoked? revoked_at.present? end
Private Instance Methods
token_exists?()
click to toggle source
# File lib/secretkeeper/access_token.rb, line 47 def token_exists? AccessToken.exists?(token: access_token, refresh_token: r_token) end
token_params()
click to toggle source
# File lib/secretkeeper/access_token.rb, line 51 def token_params { token: access_token, refresh_token: r_token, expires_in: token_expires_in } end