Class: JwtRest::Tokens::Basic

Inherits:
Object
  • Object
show all
Defined in:
lib/jwt_rest/tokens/basic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username: nil, password: nil, token: nil) ⇒ Basic

Returns a new instance of Basic.



6
7
8
9
10
# File 'lib/jwt_rest/tokens/basic.rb', line 6

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

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



4
5
6
# File 'lib/jwt_rest/tokens/basic.rb', line 4

def password
  @password
end

#tokenObject (readonly)

Returns the value of attribute token.



4
5
6
# File 'lib/jwt_rest/tokens/basic.rb', line 4

def token
  @token
end

#usernameObject (readonly)

Returns the value of attribute username.



4
5
6
# File 'lib/jwt_rest/tokens/basic.rb', line 4

def username
  @username
end

Instance Method Details

#decoder(target) ⇒ Object



26
27
28
# File 'lib/jwt_rest/tokens/basic.rb', line 26

def decoder(target)
  Base64.decode64(target)
end

#encoder(target) ⇒ Object



22
23
24
# File 'lib/jwt_rest/tokens/basic.rb', line 22

def encoder(target)
  Base64.encode64(target).gsub("\n", "")
end

#load_credentialsObject



17
18
19
20
# File 'lib/jwt_rest/tokens/basic.rb', line 17

def load_credentials
  @token = encoder("#{username}:#{password}")
  self
end

#load_tokenObject



12
13
14
15
# File 'lib/jwt_rest/tokens/basic.rb', line 12

def load_token
  @username, @password = decoder(@token).split(":")
  self
end