Module: Wepay::OAuth

Included in:
Wepay
Defined in:
lib/wepay/oauth.rb

Instance Method Summary collapse

Instance Method Details

#authorization_url(redirect_uri) ⇒ String

Returns URL to redirect user to Wepay Authorization page.

Parameters:

  • redirect_uri (String)

    The uri the user will be redirected to after authorization. Must have the same domain as the application.

Returns:

  • (String)

    URL to redirect user to Wepay Authorization page



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/wepay/oauth.rb', line 9

def authorization_url(redirect_uri)
  url = URI.parse(Wepay.oauth_authorization_endpoint)

  query = {
    client_id:    Wepay.client_id,
    scope:        Wepay.scope,
    redirect_uri: redirect_uri
  }

  url.query = query.map { |k, v| "#{k}=#{v}" }.join("&")
  url.to_s
end

#get_access_token(code, redirect_uri) ⇒ Hashie::Mash

Parameters:

  • code (String)

    The authorization code used to get the access token

  • redirect_uri (String)

    The uri the user was redirected to after authorization. Must be the same as passed in /oauth2/authorize

Returns:

  • (Hashie::Mash)


27
28
29
30
# File 'lib/wepay/oauth.rb', line 27

def get_access_token(code, redirect_uri)
  client = Wepay::Client::Token.new
  client.get_access_token(code, redirect_uri)
end