Hey there. I’m new to pack building. I’ve been able to practice building a few packs that connect to external APIs. One that is giving me a hard time is the microsoft graph api authentication. I used the sample microsoft API setup code and passed in my client id and secret. However, when I try to authenticate in a doc, I get the below error. What am I missing here?
Authorization failed
5 mins ago
Overview: Authorization failed
Path
/frontendAuth/packs/oauth2/14044/code
Error
code is required but is either missing or invalid
User ID
190697
Pack Version
10
Pack ID
14044
Request ID
eyJjc3JmVG9rZW4iOiJDR1FObldPNkVsOHo2TGE3IiwiZXhwaXJ5TXNlYyI6MTY1OTYxMjAwNDg0OX0
Created at
Aug 4, 2022 @ 07:15:07
Here is the code I used:
pack.setUserAuthentication({
type: coda.AuthenticationType.OAuth2,
authorizationUrl:
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
tokenUrl: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
// eslint-disable-next-line max-len
// Learn more: https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent
scopes: [
"https://graph.microsoft.com/.default",
],
// Additional parameters to ensure a refresh_token is returned.
additionalParams: {
prompt: "consent",
},
// Enable PKCE (optional but recommended).
useProofKeyForCodeExchange: true,
// Determines the display name of the connected account.
getConnectionName: async function (context) {
let response = await context.fetcher.fetch({
method: "GET",
url: "https://graph.microsoft.com/v1.0/me",
});
let user = response.body;
return user.displayName;
},
});
// Allow the pack to make requests to Microsoft.
pack.addNetworkDomain("microsoft.com");