Class: Knock::AuthToken

Inherits:
Object
  • Object
show all
Defined in:
app/model/knock/auth_token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload: {}, token: nil) ⇒ AuthToken

Returns a new instance of AuthToken.



7
8
9
10
11
12
13
14
15
16
17
# File 'app/model/knock/auth_token.rb', line 7

def initialize payload: {}, token: nil
  if token.present?
    @payload, _ = JWT.decode token, decode_key, true, options
    @token = token
  else
    @payload = payload
    @token = JWT.encode claims.merge(payload),
      secret_key,
      Knock.token_signature_algorithm
  end
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



5
6
7
# File 'app/model/knock/auth_token.rb', line 5

def token
  @token
end

Instance Method Details

#current_userObject



19
20
21
# File 'app/model/knock/auth_token.rb', line 19

def current_user
  @current_user ||= Knock.current_user_from_token.call @payload
end