module Card::Auth::ApiKey

methods for setting current account

Public Instance Methods

find_account_by_api_key(api_key) click to toggle source

find +*account card by +*api card @param api_key [String] @return [+*account card, nil]

# File lib/card/auth/api_key.rb, line 30
def find_account_by_api_key api_key
  find_account_by :api_key, api_key.strip
end
signin_with(token: nil, api_key: nil) click to toggle source
# File lib/card/auth/api_key.rb, line 7
def signin_with token: nil, api_key: nil
  if token
    signin_with_token token
  elsif api_key
    signin_with_api_key api_key
  else
    signin_with_session
  end
end
signin_with_api_key(api_key) click to toggle source

set the current user based on api_key

# File lib/card/auth/api_key.rb, line 18
def signin_with_api_key api_key
  account = find_account_by_api_key api_key
  unless account&.authenticate_api_key api_key
    raise Card::Error::PermissionDenied, "API key authentication failed"
  end

  signin account.left_id
end