Closed iuioiua closed 1 year ago
Gently pinging @cmd-johnson.
Hey there! Sorry for the late reply.
You're on the right track! When the refresh token is expired, the server should return an error response with the error
field set to invalid_grant
(as per RFC6749 section 5.2):
try {
await oauth2Client.refreshToken.refresh(refreshToken);
} catch (error) {
if (error instanceof OAuth2ResponseError && error.error === "invalid_grant") {
// the refresh token is probably expired
return null;
}
throw error;
}
Thanks for getting back to me! OAuth2ResponseError
is type-only export, so error instance OAuth2ResponseError
doesn't work. Perhaps, the class should be exported instead of just the type. Could we say the same of the other errors?
Huh, I totally missed that. Absolutely, those errors shouldn't just be exported as types.
That's an easy fix though! Check out https://deno.land/x/oauth2_client@v1.0.2/mod.ts
:slightly_smiling_face:
Nice! Thank you. Implemented in https://github.com/denoland/deno_kv_oauth/pull/131
When using
oauth2Client.refreshToken.refresh()
, how do I handle when the refresh token has expired? AFAIK an error is thrown, but I'm not sure which error. My thoughts are it'd be handled like this: