Sha256: 58870cde91a0499e666291df2cfc3d012c54fd064d49d2b74a05c65aa1566374

Contents?: true

Size: 978 Bytes

Versions: 15

Compression:

Stored size: 978 Bytes

Contents

require "jwt"

class Card
  module Auth
    # methods for setting current account
    module ApiKey
      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

      # set the current user based on api_key
      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

      # find +\*account card by +\*api card
      # @param api_key [String]
      # @return [+*account card, nil]
      def find_account_by_api_key api_key
        find_account_by :api_key, api_key.strip
      end

      def api_act?
        Env.controller&.try(:authenticators)&.values&.compact.present?
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
card-mod-api_key-0.18.1 lib/card/auth/api_key.rb
card-mod-api_key-0.18.0 lib/card/auth/api_key.rb
card-mod-api_key-0.17.0 lib/card/auth/api_key.rb
card-mod-api_key-0.16.0 lib/card/auth/api_key.rb
card-mod-api_key-0.15.6 lib/card/auth/api_key.rb
card-mod-api_key-0.15.5 lib/card/auth/api_key.rb
card-mod-api_key-0.15.4 lib/card/auth/api_key.rb
card-mod-api_key-0.15.3 lib/card/auth/api_key.rb
card-mod-api_key-0.15.2.pre1 lib/card/auth/api_key.rb
card-mod-api_key-0.15.1.1 lib/card/auth/api_key.rb
card-mod-api_key-0.15.1 lib/card/auth/api_key.rb
card-mod-api_key-0.15.0 lib/card/auth/api_key.rb
card-mod-api_key-0.14.2 lib/card/auth/api_key.rb
card-mod-api_key-0.14.1 lib/card/auth/api_key.rb
card-mod-api_key-0.14.0 lib/card/auth/api_key.rb