Hello Calendly Developer Community,
I'm currently working on integrating Calendly into our Node.js/Express application to allow users to manage their appointments. I have successfully directed users to the authorization URL, and they can authorize the application successfully. However, I am encountering an issue during the OAuth token exchange phase.
Process Overview:
-
User Authorization: Users are redirected to the following URL to authorize:
https://auth.calendly.com/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_ENCODED_REDIRECT_URI&response_type=code
Upon successful authorization, they are redirected back with an authorization code.
-
Authorization Code Example:
Code received: qc_wV5N-WYdM8ROY-xZJRVwQUp2nx_mY3ONn1i3Yb_Q
-
Token Exchange Request: I then make a POST request to exchange the authorization code for an access token:
curl --request POST \ --url https://auth.calendly.com/oauth/token \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'grant_type=authorization_code' \ --data-urlencode 'code=qc_wV5N-WYdM8ROY-xZJRVwQUp2nx_mY3ONn1i3Yb_Q' \ --data-urlencode 'redirect_uri=https://backend.webboar.com:3000/api/integrations/add/calendly'
Error Received: Upon making the token exchange request, I receive the following error:
{ "error": "invalid_grant", "error_description": "The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client." }
This error occurs even though I am using the same redirect_uri
as in the initial authorization request and the code is freshly received.
Could anyone suggest what might be going wrong or how to debug this issue further? Any insights or similar experiences shared would be greatly appreciated. I am using Node.js/Express and handling the OAuth flow manually, as well as attempting to use the simple-oauth2
library for managing OAuth flows.
Thank you for any help you can provide!