We have seen what is OAuth and how Freshworks apps use it. Let's look at how it actually works by using it in our app.
To create OAuth credentials for Asana:
- Go to the Asana Developer Console at Asana Developer Console.
- Log in with your Asana account.
- Click on "Create new app" card.
- Fill in the app details such as "App Name" and "purpose".
- Click "Create App" to generate your OAuth credentials.
- Note down the "Client ID" and "Client Secret" provided by Asana securely. These will be used in your app’s OAuth configuration.
To create OAuth credentials for GitHub:
- Go to GitHub and log in to your account.
- Navigate to GitHub Developer Settings.
- Under "OAuth Apps", click "New OAuth App".
- Fill out the form with your app’s details:
- "Application Name": Your app's name.
- "Homepage URL": The URL of your app.
- "Authorization callback URL": The URL where users will be sent after authorization. Find the redirect URL for Freshworks apps in the documentation.
- Click "Register Application" to generate your OAuth credentials.
- You will receive a "Client ID" and "Client Secret". These credentials are required for your app’s OAuth configuration.
Using the credentials involves configuring the OAuth settings in your app:
- Let’s include the OAuth configuration file in your app by creating a JSON file under the “/config” folder with the name "oauth_config.json".
- Add the following content to the file.
1{
2 "integrations": {
3 "asana": {
4 "display_name": "Asana",
5 "client_id": "YOUR_CLIENT_ID",
6 "client_secret": "YOUR_CLIENT_SECRET",
7 "authorize_url": "https://app.asana.com/-/oauth_authorize",
8 "token_url": "https://app.asana.com/-/oauth_token",
9 "options": {
10 "scope": "default"
11 },
12 "token_type": "account"
13 },
14 "github": {
15 "display_name": "GitHub",
16 "client_id": "YOUR_CLIENT_ID",
17 "client_secret": "YOUR_CLIENT_SECRET",
18 "authorize_url": "https://github.com/login/oauth/authorize",
19 "token_url": "https://github.com/login/oauth/access_token",
20 "options": {
21 "scope": "repo"
22 },
23 "token_type": "account"
24 }
25 }
26}
Replace YOUR_ASANA_CLIENT_ID, YOUR_ASANA_CLIENT_SECRET, YOUR_GITHUB_CLIENT_ID, and YOUR_GITHUB_CLIENT_SECRET with the actual credentials you obtained from Asana and GitHub.
Testing
Testing the OAuth handshake ensures that your app can securely obtain access tokens:
- Run the app with fdk run command again.
- Install the app from the Custom App section in the Marketplace and it will process the authorisation.
- The app will request for the installation parameters, then OAuth iparams, and then it will execute the OAuth handshake and user will be requested to authorise in the Asana and GitHub's authorisation page with the relevant scope and OAuth credential name defined.
- After you authorise as a user, the app will proceed to install and complete the installation.
- If any of the OAuth handshake fails, it will be returned to the Freshworks Marketplace page with proper error message if any of the inputs in the OAuth credentials or configurations are wrong. Correct them and install the app again to retest until the app installation completes successfully.
We have added the OAuth configuration to the app. Now, let’s use it in the APIs made to Asana and GitHub.