Closed relaxedtomato closed 10 months ago
Hey @relaxedtomato, I would like to work on this one.
@amit-ksh awesome - connect if you have questions. We can get you setup with our new dashboard for testing purposes.
Send your email over to devrel
at nylas.com
with the subject: hacktoberfest23
, and we'll quickly send account details 👍
@relaxedtomato, I'm having some trouble creating grants using the nylas.auth.grants.create
method but it requires a refreshToken
. So, I attempted to obtain a refreshToken
using the nylas.auth.exchangeCodeForToken
, but unfortunately, it resulted in an error. Could you please assist me with this issue?
My Code-
const { code } = req.query;
const resp = await nylas.auth.exchangeCodeForToken({
code,
});
Error I got when exchangeCodeForToken
is called-
/nylas-hacktoberfest-2023/code-samples/grant/node/create/node_modules/nylas/lib/esm/apiClient.js:98
error = new NylasOAuthError(camelCaseError, response.status);
^
NylasOAuthError: Internal error, contact administrator
at APIClient.request (file:///D:/personal/open-source/nylas-hacktoberfest-2023/code-samples/grant/node/create/node_modules/nylas/lib/esm/apiClient.js:98:29)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///D:/personal/open-source/nylas-hacktoberfest-2023/code-samples/grant/node/create/index.js:28:16 {
error: 'internal_error',
errorCode: 500,
errorDescription: 'Internal error, contact administrator',
errorUri: 'https://accounts.nylas.io/#tag/Event-Codes',
statusCode: 500
}
@amit-ksh - will take a look today 👍
@amit-ksh, just confirming two items:
are you able to share a code sample or branch that I can take a look at?
So from the SDK docs, exchangeCodeForToken
doesn't exist:
@amit-ksh - sorry, just realized I confused languages, let me take another look.
Here is the Node SDK Reference: https://nylas-nodejs-sdk-reference.pages.dev/
@amit-ksh:
I noticed a few items:
const newGrants = await nylas.auth.grants.create({
I see, this accesses the nylas.grants
public method. So I have one thought, once you authenticate a user, does the following list grants?
nylas.auth.grants.list
?Once we authenticate a user, a grant should be created for them. You can test this out using the dashboard as well.
hey @relaxedtomato! I'm getting the error on this line const resp = await nylas.auth.exchangeCodeForToken
. It returned the 500 status when I did some debugging.
I believe this line const newGrants = await nylas.auth.grants.create
is not causing the issue.
Also, I tried creating grants using the dashboard it's working as expected as well as this method nylas.auth.grants.list
.
Okay, let me try this out shortly!
I tried to pass all the arguments that I have to exchangeCodeForToken
method and now it's working I'm not getting `refreshToken
in response.
const resp = await nylas.auth.exchangeCodeForToken({
code,
clientSecret: process.env.CLIENT_SECRET,
clientId: process.env.CLIENT_ID,
redirectUri: "http://localhost:3000/oauth/exchange",
});
exchangeCodeForToken
function-{
accessToken: 'token',
grantId: 'id',
email: 'some@gmail.com',
expiresIn: 3600,
idToken: 'token',
tokenType: 'Bearer',
scope: 'scope1 scope2'
}
Also, when I list grants using this nylas.auth.grants.list
, I'm getting all the emails I authenticated to but the same is not shown in the Nylas Dashboard.
@amit-ksh - this looks good, since I see that you are receiving the grandId
in return which can be used for subsequent requests.
Let's prepare a PR and I will review 👍
Okay, let me take a look at the PR!
Using Nylas Node v3 SDK, create a code sample to create a user grant