Module: Card::Auth::ApiKey
- Defined in:
- lib/card/auth/api_key.rb
Overview
methods for setting current account
Instance Method Summary collapse
- #api_act? ⇒ Boolean
-
#find_account_by_api_key(api_key) ⇒ +*account card?
find *account card by *api card.
- #signin_with(token: nil, api_key: nil) ⇒ Object
-
#signin_with_api_key(api_key) ⇒ Object
set the current user based on api_key.
Instance Method Details
#api_act? ⇒ Boolean
34 35 36 |
# File 'lib/card/auth/api_key.rb', line 34 def api_act? Env.controller&.try(:authenticators)&.values&.compact.present? end |
#find_account_by_api_key(api_key) ⇒ +*account card?
find *account card by *api card
30 31 32 |
# 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) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# 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) ⇒ Object
set the current user based on api_key
18 19 20 21 22 23 24 25 |
# 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 |