Class: CslCli::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/csl_cli/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_url) ⇒ Auth

Returns a new instance of Auth.



14
15
16
# File 'lib/csl_cli/auth.rb', line 14

def initialize(api_url)
  @csl_app_url = api_url
end

Instance Attribute Details

#csl_app_urlObject (readonly)

Returns the value of attribute csl_app_url.



12
13
14
# File 'lib/csl_cli/auth.rb', line 12

def csl_app_url
  @csl_app_url
end

#decoded_tokenObject (readonly)

Returns the value of attribute decoded_token.



11
12
13
# File 'lib/csl_cli/auth.rb', line 11

def decoded_token
  @decoded_token
end

#tokenObject (readonly)

Returns the value of attribute token.



10
11
12
# File 'lib/csl_cli/auth.rb', line 10

def token
  @token
end

Instance Method Details

#login(email, password) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/csl_cli/auth.rb', line 18

def (email, password)
  credentials = {auth: {email: email, password: password}}.to_json
  request_auth = CslCli::Request::Post.new(@csl_app_url + '/user_token', credentials, {"Content-Type" => "application/json"})
  if request_auth.code < 300
    @token = JSON.parse(request_auth.response.body)["jwt"]
    @decoded_token = {}
    @decoded_token['header'] = JSON.parse(Base64.decode64(@token.split('.')[0]))
    @decoded_token['payload'] = JSON.parse(Base64.decode64(@token.split('.')[1]))

    true
  end
end