Class: Ros::ApiTokenStrategy

Inherits:
Warden::Strategies::Base
  • Object
show all
Defined in:
lib/ros/api_token_strategy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_key_idObject

Returns the value of attribute access_key_id.



5
6
7
# File 'lib/ros/api_token_strategy.rb', line 5

def access_key_id
  @access_key_id
end

#auth_stringObject

Returns the value of attribute auth_string.



5
6
7
# File 'lib/ros/api_token_strategy.rb', line 5

def auth_string
  @auth_string
end

#auth_typeObject

Returns the value of attribute auth_type.



5
6
7
# File 'lib/ros/api_token_strategy.rb', line 5

def auth_type
  @auth_type
end

#secret_access_keyObject

Returns the value of attribute secret_access_key.



5
6
7
# File 'lib/ros/api_token_strategy.rb', line 5

def secret_access_key
  @secret_access_key
end

#tokenObject

Returns the value of attribute token.



5
6
7
# File 'lib/ros/api_token_strategy.rb', line 5

def token
  @token
end

#urnObject

Returns the value of attribute urn.



5
6
7
# File 'lib/ros/api_token_strategy.rb', line 5

def urn
  @urn
end

Instance Method Details

#authenticate!Object



19
20
21
22
23
24
# File 'lib/ros/api_token_strategy.rb', line 19

def authenticate!
  user = send("authenticate_#{auth_type}") if auth_type.in? %w(basic bearer)
  return success!(user) if user
  # This is returned to IAM service
  fail!({ errors: [{ status: 401, code: 'unauthorized', title: 'Unauthorized' }] }.to_json)
end

#authenticate_basicObject



26
27
28
29
30
31
32
33
# File 'lib/ros/api_token_strategy.rb', line 26

def authenticate_basic
  # TODO: Credential.authorization must be an instance variable
  Ros::Sdk::Credential.authorization = auth_string
  return unless credential = Ros::IAM::Credential.where(access_key_id: access_key_id).first
  "Ros::IAM::#{credential.owner_type}".constantize.find(credential.owner_id).first
# NOTE: Swallow the auth error and return nil which causes user to be nil, which cuases FailureApp to be invoked
rescue JsonApiClient::Errors::NotAuthorized => e
end

#authenticate_bearerObject



35
36
37
38
39
40
41
42
43
# File 'lib/ros/api_token_strategy.rb', line 35

def authenticate_bearer
  return unless urn = Urn.from_jwt(token)
  return unless urn.model_name.in? %w(Root User)
  # TODO: Credential.authorization must be an instance variable
  Ros::Sdk::Credential.authorization = auth_string
  "Ros::IAM::#{urn.model_name}".constantize.find_by_urn(urn.resource_id)
# NOTE: Swallow the auth error and return nil which causes user to be nil, which cuases FailureApp to be invoked
rescue JsonApiClient::Errors::NotAuthorized => e
end

#valid?Boolean

Returns:

  • (Boolean)


17
# File 'lib/ros/api_token_strategy.rb', line 17

def valid?; token.present? end