Class: Gaku::Api::AuthenticateUser

Inherits:
Object
  • Object
show all
Includes:
SimpleCommand
Defined in:
app/services/gaku/api/authenticate_user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, password:) ⇒ AuthenticateUser

Returns a new instance of AuthenticateUser.



9
10
11
12
# File 'app/services/gaku/api/authenticate_user.rb', line 9

def initialize(username:, password:)
  @username = username
  @password = password
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'app/services/gaku/api/authenticate_user.rb', line 7

def password
  @password
end

#usernameObject

Returns the value of attribute username.



7
8
9
# File 'app/services/gaku/api/authenticate_user.rb', line 7

def username
  @username
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
# File 'app/services/gaku/api/authenticate_user.rb', line 14

def call
  if user
    secret = SecureRandom.hex(64)
    $redis.set("token:#{jti}", secret, ex: 20.minutes)
    {
      auth_token: JsonWebToken.encode({user_id: user.id}, exp: 3.minutes.from_now, jti: jti, secret: secret),
      refresh_token: JsonWebToken.encode({user_id: user.id}, exp: 20.minutes.from_now, jti: jti, secret: secret)
    }
  end
end