Sha256: 03f49739ae7e3b8efcc47a878ae46215a8535af759c18142a1c235103ffbff2e

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

# rubocop:disable all
module OAuth2
  module Strategy
    # The Token Exchange strategy
    #
    # @see https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-03#section-4.1
    class TokenExchange < Base
      GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:token-exchange'

      # Not used for this strategy
      #
      # @raise [NotImplementedError]
      def authorize_url
        fail(NotImplementedError, 'The authorization endpoint is not used in this strategy')
      end

      # Retrieve an access token given the specified End User username and password.
      #
      # @param [String] username the End User username
      # @param [String] password the End User password
      # @param [Hash] params additional params
      def get_token(actor_token, actor_token_type, subject_token, subject_token_type, params = {}, opts = {})
        params = {'grant_type'          => GRANT_TYPE,
                  'actor_token'         => actor_token,
                  'actor_token_type'    => actor_token_type,
                  'subject_token'       => subject_token,
                  'subject_token_type'  => subject_token_type
        }.merge(params)
        @client.get_token(params, opts)
      end
    end
  end

  # Add strategy to OAuth2::Client
  class Client
    def token_exchange
      @token_exchange ||= OAuth2::Strategy::TokenExchange.new(self)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
aptible-auth-1.2.5 lib/oauth2/strategy/token_exchange.rb
aptible-auth-1.2.4 lib/oauth2/strategy/token_exchange.rb
aptible-auth-1.2.3 lib/oauth2/strategy/token_exchange.rb
aptible-auth-1.2.2 lib/oauth2/strategy/token_exchange.rb