Module: HelloSign::Api::OAuth

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

Overview

Contains all the API calls for OAuth workflows. OAuth allows you to perform actions on behalf of other users after they grant you the authorization to do so. See our OAuth API documentation (app.hellosign.com/api/oauthWalkthrough) for more information.

Author:

  • hellosign

Instance Method Summary collapse

Instance Method Details

#get_oauth_token(opts) ⇒ Hash

Retrieves 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:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • state (String)

    Random security value that was used when you created oauth_url for a specific user.

  • code (String)

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

  • client_id (String)

    The ApiApp Client ID.

  • client_secret (String)

    The secret token of your ApiApp.

Returns:

  • (Hash)

    OAuth data of the user



58
59
60
61
62
63
# File 'lib/hello_sign/api/oauth.rb', line 58

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

Creates a new user and retrieves the 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.

Examples:

client. email_address: '[email protected]'

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • email_address (String)

    New user’s email address.

Returns:

  • (Hash)

    details about new user, including OAuth data



87
88
89
90
91
92
# File 'lib/hello_sign/api/oauth.rb', line 87

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

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

#oauth_url(state) ⇒ Object

Returns the OAuth URL where users can authorize 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:

  • state (String)

    Random security value that must match throughout the user’s flow.



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

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

#refresh_oauth_token(opts) ⇒ Hash

Refreshes the user’s OAuth token.

Examples:

client.refresh_oauth_token refresh_token: 'hNTI2MTFmM2VmZDQxZTZjOWRmZmFjZmVmMGMyNGFjMzI2MGI5YzgzNmE3'

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • refresh_token (String)

    The token provided when the access token has expired.

Returns:

  • (Hash)

    Refreshed OAuth info



72
73
74
75
76
77
# File 'lib/hello_sign/api/oauth.rb', line 72

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