Class: Foobara::Auth::AuthenticateWithApiKey

Inherits:
Command
  • Object
show all
Defined in:
foobara-auth-0.1.1/src/authenticate_with_api_key.rb

Defined Under Namespace

Classes: ApiKeyDoesNotExistError, InvalidApiKeyError

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

install!

Methods included from TruncatedInspect

#inspect, truncating

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Instance Attribute Details

#api_key_idObject

Returns the value of attribute api_key_id.



37
38
39
# File 'src/authenticate_with_api_key.rb', line 37

def api_key_id
  @api_key_id
end

#api_key_recordObject

Returns the value of attribute api_key_record.



37
38
39
# File 'src/authenticate_with_api_key.rb', line 37

def api_key_record
  @api_key_record
end

#api_key_secretObject

Returns the value of attribute api_key_secret.



37
38
39
# File 'src/authenticate_with_api_key.rb', line 37

def api_key_secret
  @api_key_secret
end

#expires_atObject

Returns the value of attribute expires_at.



37
38
39
# File 'src/authenticate_with_api_key.rb', line 37

def expires_at
  @expires_at
end

#userObject

Returns the value of attribute user.



37
38
39
# File 'src/authenticate_with_api_key.rb', line 37

def user
  @user
end

Instance Method Details

#determine_api_key_id_and_secretObject



39
40
41
# File 'src/authenticate_with_api_key.rb', line 39

def determine_api_key_id_and_secret
  self.api_key_id, self.api_key_secret = api_key.split("_")
end

#executeObject



27
28
29
30
31
32
33
34
35
# File 'src/authenticate_with_api_key.rb', line 27

def execute
  determine_api_key_id_and_secret
  load_api_key_record
  verify_api_key

  load_user

  user_and_credential
end

#load_api_key_recordObject



43
44
45
46
47
# File 'src/authenticate_with_api_key.rb', line 43

def load_api_key_record
  self.api_key_record = Types::Token.load(api_key_id)
rescue Foobara::Entity::NotFoundError
  add_runtime_error(ApiKeyDoesNotExistError)
end

#load_userObject



57
58
59
# File 'src/authenticate_with_api_key.rb', line 57

def load_user
  self.user ||= Types::User.that_owns(api_key_record, "api_keys")
end

#user_and_credentialObject



61
62
63
# File 'src/authenticate_with_api_key.rb', line 61

def user_and_credential
  [user, api_key_record]
end

#verify_api_keyObject



49
50
51
52
53
54
55
# File 'src/authenticate_with_api_key.rb', line 49

def verify_api_key
  valid = run_subcommand!(VerifyToken, token_string: api_key)

  unless valid[:verified]
    add_runtime_error(InvalidApiKeyError)
  end
end