Sha256: 8f51b15da8a3e4ae0ff1fc8237943064c24fb721afb6f4b22ff8f5e0094ed975

Contents?: true

Size: 979 Bytes

Versions: 1

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true

class GlobusClient
  # The namespace for the "login" command
  class Authenticator
    def self.token(client_id, client_secret, auth_url)
      new(client_id, client_secret, auth_url).token
    end

    def initialize(client_id, client_secret, auth_url)
      @client_id = client_id
      @client_secret = client_secret
      @auth_url = auth_url
    end

    # Request an access_token
    def token
      response = connection.post('/v2/oauth2/token', form_data)

      UnexpectedResponse.call(response) unless response.success?

      JSON.parse(response.body)['access_token']
    end

    private

    attr_reader :client_id, :client_secret, :auth_url

    def connection
      Faraday.new(url: auth_url)
    end

    def form_data
      {
        client_id:,
        client_secret:,
        encoding: 'form',
        grant_type: 'client_credentials',
        scope: 'urn:globus:auth:scope:transfer.api.globus.org:all'
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
globus_client-0.14.0 lib/globus_client/authenticator.rb