OAuth handshake failing and unable to store access_token

Hi

I am trying to complete OAuth flow using freshservice serverless app but facing below issues

Here is oauth_config_json file

{
    "client_id": "<%= oauth_iparams.client_id %>",
    "client_secret": "<%= oauth_iparams.client_secret %>",
    "authorize_url": "https://<%= oauth_iparams.domain %>/authorize-app/<%= oauth_iparams.client_id %>",
    "token_url": "https://domain.com/api/integrations/oauth/token?client_id=<%= oauth_iparams.client_id %>&client_secret=<%= oauth_iparams.client_secret %>&redirect_uri=http://localhost:10001/auth/callback&grant_type=authorization_code&code=access_code",
    "options": {
        "scope": "write"
    },
    "token_type": "account",
    "oauth_iparams": {
        "domain": {
            "display_name": "Domain",
            "description": "Please enter your domain",
            "type": "text",
            "required": true
        },
        "client_id": {
            "display_name": "Client ID",
            "description": "Please enter your client ID",
            "type": "text",
            "required": true
        },
        "client_secret": {
            "display_name": "Client Secret",
            "description": "Please enter your client secret",
            "type": "text",
            "secure": true,
            "required": true
        }
    }
}

Below is redirection_uri

http://localhost:10001/auth/callback?code=32ecb980ad1f1496&state=19da57fe-6c41-4486-9793-564902aeea37

fresh__101_101_oauth_appstate parameter store in localstore but not the code

Received code in redirect_uri but getting below error :

InternalOAuthError: Failed to obtain access token
    at OAuth2Strategy._createOAuthError (C:\Users\anushka.ahir\AppData\Roaming\npm\node_modules\fdk\node_modules\passport-oauth2\lib\strategy.js:423:17)
    at C:\Users\anushka.ahir\AppData\Roaming\npm\node_modules\fdk\node_modules\passport-oauth2\lib\strategy.js:177:45
    at C:\Users\anushka.ahir\AppData\Roaming\npm\node_modules\fdk\node_modules\oauth\lib\oauth2.js:191:18
    at passBackControl (C:\Users\anushka.ahir\AppData\Roaming\npm\node_modules\fdk\node_modules\oauth\lib\oauth2.js:132:9)
    at IncomingMessage.<anonymous> (C:\Users\anushka.ahir\AppData\Roaming\npm\node_modules\fdk\node_modules\oauth\lib\oauth2.js:157:7)
    at IncomingMessage.emit (events.js:412:35)
    at endReadableNT (internal/streams/readable.js:1333:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
	

How can I send access code in the token URL?
How will the access_token and refresh token saved in localstore?
How to handle OAuth callback?

Thanks!

Hi @Anushka_Ahir ,

Welcome to Freshworks Developer Community forum :bouquet:

Kindly refer this post from our developer advocate on how add OAuth in FW Apps

Regards,
Thakur

Thanks @Thakur_Ganeshsingh

I am facing problem with redirection URL in third party
In third party callback URL is not allowed with localhost

So I change my callback URL to my ipaddress like http://000.00.00.00:10001/auth/callback

So How can I change my redirection_uri in oauth_config file?
Is there is way to change callbackURL in freshservice serverless app?

1 Like

@Raviraj - could you add your inputs please.

2 Likes

Hi @Anushka_Ahir,

If the third party doesn’t support the localhost URL, you can use the tunnel feature in FDK that will expose a publicly accessible URL for your local server. The localhost:10001 domain can be replaced with the ngrok domain, and the rest of the redirection URL can be appended to it.

I haven’t personally tested it with OAuth; let me know if it works.

For the token URL, only the base token URL is required to be added to the OAuth configuration in the app. The required token and redirection URL will be automatically appended by the platform.

@Anushka_Ahir

Hope you are doing well. Were you able to resolve the issue?

Regards,
Thakur

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.