Class: CslCli::Auth
- Inherits:
-
Object
- Object
- CslCli::Auth
- Defined in:
- lib/csl_cli/auth.rb
Instance Attribute Summary collapse
-
#csl_app_url ⇒ Object
readonly
Returns the value of attribute csl_app_url.
-
#decoded_token ⇒ Object
readonly
Returns the value of attribute decoded_token.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(api_url) ⇒ Auth
constructor
A new instance of Auth.
- #login(email, password) ⇒ Object
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_url ⇒ Object (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_token ⇒ Object (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 |
#token ⇒ Object (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 login(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 |