Module: HelloSign::Api::OAuth

Included in:
Client
Defined in:
lib/hello_sign/api/oauth.rb

Overview

OAuth allows you to perform actions on behalf of other users after they grant you the authorization to do so. For example, you could send signature requests on behalf of your users. This page lays out the basic steps to do that. IMPORTANT

With OAuth, you (the app owner) will be charged for all signature requests sent on behalf of other users via your app.

Instance Method Summary collapse

Instance Method Details

#get_oauth_token(opts) ⇒ Hash

Retrieving the OAuth token

Examples:

client = HelloSign::Client.new :api_key => '%apikey%', :client_id => 'cc91c61d00f8bb2ece1428035716b', :client_secret => '1d14434088507ffa390e6f5528465'
client.get_oauth_token :state => '900e06e2', :code =>'1b0d28d90c86c141'

Parameters:

  • a customizable set of options

Options Hash (opts):

  • state (String)

    variable that was used when you created oauth_url for a specific user

  • code (String)

    The authorization code passed to your callback when the user granted access

Returns:

  • oauth data of the user



35
36
37
38
39
40
# File 'lib/hello_sign/api/oauth.rb', line 35

def get_oauth_token(opts)
  opts[:client_id] = self.client_id
  opts[:client_secret] = self.client_secret
  opts[:grant_type] = 'authorization_code'
  post('/oauth/token', { :body => opts, :oauth_request => true })
end

#oauth_create_account(opts) ⇒ Hash

Create new user and get their OAuth token. The user will receive an email asking them to confirm the access being granted. Your app will not be able to perform actions on behalf of this user until they confirm.

Parameters:

  • a customizable set of options

Options Hash (opts):

  • email_address (String)

    new user email address

  • password (String)

    new user password

Returns:

  • details about new user, including oath data



62
63
64
65
66
67
# File 'lib/hello_sign/api/oauth.rb', line 62

def (opts)
  opts[:client_id] = self.client_id
  opts[:client_secret] = self.client_secret

  HelloSign::Resource::.new post('/account/create', { :body => opts })
end

#oauth_url(state) ⇒ type

Return the oath url where users can give permission for your application to perform actions on their behalf. It can be set to the value of your choice (preferably something random). You should verify it matches the expected value when validating the OAuth callback.

Parameters:

  • used for security and must match throughout the flow for a given user.

Returns:

  • description


20
21
22
# File 'lib/hello_sign/api/oauth.rb', line 20

def oauth_url(state)
  "#{self.oauth_end_point}/oauth/authorize?response_type=code&client_id=#{self.client_id}&state=#{state}"
end

#refresh_oauth_token(refresh_token) ⇒ Hash

refresh user oauth token.

Examples:

client = HelloSign::Client.new :api_key => '%apikey%', :client_id => 'cc91c61d00f8bb2ece1428035716b', :client_secret => '1d14434088507ffa390e6f5528465'
client.refresh_oauth_token :refresh_token => 'hNTI2MTFmM2VmZDQxZTZjOWRmZmFjZmVmMGMyNGFjMzI2MGI5YzgzNmE3'

Returns:

  • refreshed oauth info



51
52
53
# File 'lib/hello_sign/api/oauth.rb', line 51

def refresh_oauth_token(refresh_token)
  post('/oauth/token', { :body => { :grant_type => 'refresh_token', :refresh_token => refresh_token }, :oauth_request => true })
end