Sha256: d6eff9e2a0078524400a6d72086fe8cbef5adc2927dd463580533cf097ede23d

Contents?: true

Size: 810 Bytes

Versions: 5

Compression:

Stored size: 810 Bytes

Contents

# frozen_string_literal: true

module Icasework
  module Token
    ##
    # Generate access token for Bearer authorisation header
    #
    class Bearer
      class << self
        def generate
          new Icasework::Resource.token(payload).data
        rescue RequestError, ResponseError => e
          raise AuthenticationError, e.message
        end

        private

        def payload
          {
            grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
            assertion: Icasework::Token::JWT.generate
          }
        end
      end

      def initialize(data)
        @access_token = data.fetch(:access_token)
        @token_type = data.fetch(:token_type)
        @expires_in = data.fetch(:expires_in)
      end

      def to_s
        @access_token
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
icasework-0.1.4 lib/icasework/token/bearer.rb
icasework-0.1.3 lib/icasework/token/bearer.rb
icasework-0.1.2 lib/icasework/token/bearer.rb
icasework-0.1.1 lib/icasework/token/bearer.rb
icasework-0.1.0 lib/icasework/token/bearer.rb