Sha256: 4027fe86e7a6b534ec9c7d22fd093f1eba35cc80c5c61a4e28be6f388e9e2e74

Contents?: true

Size: 858 Bytes

Versions: 10

Compression:

Stored size: 858 Bytes

Contents

# frozen_string_literal: true

module SolidusBolt
  module Oauth
    class TokenService < SolidusBolt::BaseService
      attr_reader :authorization_code, :scope

      def initialize(authorization_code:, scope:)
        @authorization_code = authorization_code
        @scope = scope
        super
      end

      def call
        token
      end

      private

      def token
        options = build_options
        handle_result(
          HTTParty.post(
            "#{api_base_url}/#{api_version}/oauth/token",
            options
          )
        )
      end

      def build_options
        {
          body: {
            grant_type: 'authorization_code',
            code: authorization_code,
            scope: scope,
            client_id: publishable_key,
            client_secret: api_key
          }
        }
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
solidus_bolt-0.7.2 app/services/solidus_bolt/oauth/token_service.rb
solidus_bolt-0.7.1 app/services/solidus_bolt/oauth/token_service.rb
solidus_bolt-0.7.0 app/services/solidus_bolt/oauth/token_service.rb
solidus_bolt-0.6.0 app/services/solidus_bolt/oauth/token_service.rb
solidus_bolt-0.5.0 app/services/solidus_bolt/oauth/token_service.rb
solidus_bolt-0.4.0 app/services/solidus_bolt/oauth/token_service.rb
solidus_bolt-0.3.0 app/services/solidus_bolt/oauth/token_service.rb
solidus_bolt-0.2.0 app/services/solidus_bolt/oauth/token_service.rb
solidus_bolt-0.1.0 app/services/solidus_bolt/oauth/token_service.rb
solidus_bolt-0.0.1 app/services/solidus_bolt/oauth/token_service.rb