Module: Stripe::OAuth

Defined in:
lib/stripe/oauth.rb,
lib/stripe/errors.rb

Defined Under Namespace

Modules: OAuthOperations Classes: InvalidClientError, InvalidGrantError, InvalidRequestError, InvalidScopeError, OAuthError, UnsupportedGrantTypeError, UnsupportedResponseTypeError

Class Method Summary collapse

Class Method Details

.authorize_url(params = {}, opts = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/stripe/oauth.rb', line 29

def self.authorize_url(params = {}, opts = {})
  base = opts[:connect_base] || APIRequestor.active_requestor.config.connect_base

  path = "/oauth/authorize"
  path = "/express" + path if opts[:express]

  params[:client_id] = get_client_id(params)
  params[:response_type] ||= "code"
  query = Util.encode_parameters(params, :v1)

  "#{base}#{path}?#{query}"
end

.deauthorize(params = {}, opts = {}) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/stripe/oauth.rb', line 50

def self.deauthorize(params = {}, opts = {})
  opts = Util.normalize_opts(opts)
  params[:client_id] = get_client_id(params)
  OAuthOperations.execute_resource_request(
    :post, "/oauth/deauthorize", :connect, params, opts
  )
end

.get_client_id(params = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stripe/oauth.rb', line 15

def self.get_client_id(params = {})
  client_id = params[:client_id] || Stripe.client_id
  unless client_id
    raise AuthenticationError, "No client_id provided. " \
                               'Set your client_id using "Stripe.client_id = <CLIENT-ID>". ' \
                               "You can find your client_ids in your Stripe dashboard at " \
                               "https://dashboard.stripe.com/account/applications/settings, " \
                               "after registering your account as a platform. See " \
                               "https://stripe.com/docs/connect/standalone-accounts for details, " \
                               "or email [email protected] if you have any questions."
  end
  client_id
end

.token(params = {}, opts = {}) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/stripe/oauth.rb', line 42

def self.token(params = {}, opts = {})
  opts = Util.normalize_opts(opts)
  opts[:api_key] = params[:client_secret] if params[:client_secret]
  OAuthOperations.execute_resource_request(
    :post, "/oauth/token", :connect, params, opts
  )
end