class Transferwise::OAuth

Attributes

access_token[RW]

Public Class Methods

new(client_id, client_secret) click to toggle source
# File lib/transferwise/oauth.rb, line 5
def initialize(client_id, client_secret)
  @client_id, @client_secret = client_id, client_secret
end

Public Instance Methods

authorize_client() click to toggle source
# File lib/transferwise/oauth.rb, line 20
def authorize_client
  @authorize_client ||= ::OAuth2::Client.new(
    @client_id,
    @client_secret,
    { site: Transferwise.authorization_base,
      auth_scheme: :basic_auth
    }
  )
end
authorize_url(redirect_url) click to toggle source

Get the url to redirect a user to, pass the redirect_url you want the user to be redirected back to.

# File lib/transferwise/oauth.rb, line 32
def authorize_url(redirect_url)
  authorize_client.auth_code.authorize_url({redirect_uri: redirect_url})
end
client() click to toggle source

Get the OAuth 2 client

# File lib/transferwise/oauth.rb, line 10
def client
  @client ||= ::OAuth2::Client.new(
    @client_id,
    @client_secret,
    { site: Transferwise.api_base,
      auth_scheme: :basic_auth
    }
  )
end
get_access_token(code, redirect_url) click to toggle source

Get the access token. You must pass the exact same redirect_url passed to the authorize_url method

# File lib/transferwise/oauth.rb, line 38
def get_access_token(code, redirect_url)
  @access_token ||= client.auth_code.get_token(code, redirect_uri: redirect_url)
end
refresh_token(access_token, opts = {}) click to toggle source

This method is used to refresh the access token before it expires

# File lib/transferwise/oauth.rb, line 43
def refresh_token(access_token, opts = {})
  OAuth2::AccessToken.new(client, access_token, opts).refresh!
end