Sha256: 32cb4afe8c110327d945cbe2256bf86e2ca00b38fcd6d695335b513eaf0a7ed0

Contents?: true

Size: 888 Bytes

Versions: 7

Compression:

Stored size: 888 Bytes

Contents

# frozen_string_literal: true

require 'warden/jwt_auth/errors'

module Warden
  module JWTAuth
    # Layer above token encoding which directly encodes a user to a JWT
    class UserEncoder
      attr_reader :helper

      def initialize
        @helper = PayloadUserHelper
      end

      # Encodes a user for given scope into a JWT. Payload generated includes a
      # `sub` claim which is build calling `jwt_subject` in `user`, and a custom
      # `scp` claim which value is `scope` as a string. The result of
      # calling `jwt_payload` in user is also merged into the payload.
      #
      # @param user [Interfaces::User] an user, whatever it is
      # @param scope [Symbol] Warden scope
      # @return [String] encoded JWT
      def call(user, scope)
        payload = helper.payload_for_user(user, scope)
        TokenEncoder.new.call(payload)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
warden-jwt_auth-0.2.1 lib/warden/jwt_auth/user_encoder.rb
warden-jwt_auth-0.2.0 lib/warden/jwt_auth/user_encoder.rb
warden-jwt_auth-0.1.4 lib/warden/jwt_auth/user_encoder.rb
warden-jwt_auth-0.1.3 lib/warden/jwt_auth/user_encoder.rb
warden-jwt_auth-0.1.2 lib/warden/jwt_auth/user_encoder.rb
warden-jwt_auth-0.1.1 lib/warden/jwt_auth/user_encoder.rb
warden-jwt_auth-0.1.0 lib/warden/jwt_auth/user_encoder.rb