Prerequisites
Ensure that you:
- Register your app in the third-party developer portal. Once registered, you will be issued a client_id and client_secret to perform OAuth handshake with the provider.
- Provide the redirect URL for your app in the third-party developer portal.
- Testing: http://localhost:10001/auth/callback
- Production: https://oauth.freshdev.io/auth/callback
Set up OAuth configuration file
Update the following fields in the config/oauth_config.json file.
Field | Description |
---|---|
client_id Mandatory | Once you register your app in the third-party developer portal, you will be issued a client ID for your app. |
client_secret Mandatory | Once you register your app in the third-party developer portal, you will be issued a client secret for your app. |
authorize_url Mandatory | Third-party authorization request URL. |
token_url Mandatory | Request URL for the access token. |
options | The options field can be used to send:
|
token_type Mandatory | Specifies the level of access for the access token. We support the following values:
|
oauth_iparams | Certain OAuth providers, such as Shopify, have unique authorization URLs for every account. The oauth_iparams enable you to retrieve these values from the installer before the OAuth handshake occurs. These parameters are configured in the same manner as the installation parameters. Only parameters of type text are supported. |
Define OAuth request
- Provide a snapshot of the request to be made to the third-party domain, in config/requests.json.
- Use the access_token variable in <requestTemplateName>.schema.header.Authorization.
- Set <requestTemplateName>.options.isOAuth as true.
Sample config/requests.json{ "asanaGetWorkspace": { "schema": { "method": "GET", "host": "app.asana.com", "path": "/api/1.0/workspaces", "headers": { "Authorization": "bearer <%= access_token %>", "Content-Type": "application/json" } }, "options": { "isOAuth": true } } }
- Declare the configured template (snapshot) in manifest.json.Sample manifest.json
{ … "requests": { "asanaGetWorkspace": {} } }
- Invoke the template from the app code in either app.js (for front-end app) or server.js (for serverless app).Sample app.jsSample server.js
try { let workspace = await client.request.invokeTemplate( "asanaGetWorkspace", {} ); //handle success } catch (err) { //handle error }
Test apps that use OAuth
Note:For testing, use the latest version of Chrome browser.
Open your console, navigate to your project directory, and execute the following command.
fdk run
Log in to your Freshdesk account.
Go to the page where you have enabled your app. In the address bar, append the URL with ?dev=true. For example, the URL should look like this: https://subdomain.freshdesk.com/helpdesk/tickets/1?dev=true
The first time you test your app, you need to authorize the app to access information from the third-party. In the app, click the Authorize button to redirect to the third-party domain.
The generated token is stored in:
- The .fdk/localstore file for account level.
- The browser's localStorage for agent level.