-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot read properties of undefined (reading 'access_token') #151
Comments
OAuth2Token should be of type @evert can you check this issue please |
Please share your code so I can reproduce this issue! Redact any secrets. I want to see your config + it would also be helpful to see an example of the url you're parsing (also redact any tokens) |
const client = new OAuth2Client({
authorizationEndpoint,
tokenEndpoint,
clientSecret,
clientId,
});
async function createAuthorizationUri(
state: string,
redirect_uri,
): Promise<string> {
const authorizationUri = await client.authorizationCode.getAuthorizeUri({
redirectUri: redirect_uri,
state: state,
scope: ["read:user"],
});
return authorizationUri;
}
async function validateAuthorizationCode(code: string, redirect_uri): Promise<object> {
const token = await client.authorizationCode.getToken({ code, redirect_uri });
return token;
} its the same code that i got google auth working, but instead for github doesn't work (it throws an error) |
Could you share the configuration values you're using? |
sorry for the late reply const client = new OAuth2Client({
authorizationEndpoint: "https://github.com/login/oauth/authorize",
tokenEndpoint: "https://github.com/login/oauth/access_token",
clientSecret,
clientId,
}); as the Github oauth documentation. |
I started testing this, and at the very least this line is wrong (Typescript should error on this):
Note that So it looks like Github actually 2 bugs, not this library. The issue is that Github replies with a A second issue is that Github responds with |
I also submitted a bug report here: https://github.com/orgs/community/discussions/135818 Lastly, i think the feedback in this library could be a bit better: |
I understand. Given that it works fine with other libraries, do you think the issue lies on |
It's 100% a Github issue, but adding the |
@evert It would be great if you could add these workarounds to avoid writing extra code. the this line should be achieved on the If these headers are the default, the Accept header should be included here |
one more thing OAuth2Token should be keys of |
Yes, as I said I intend to add these workarounds.
OAuth2 is a standard format. We definitely do know what the format will be. |
@evert how can i get the |
OpenID Connect support is out of scope for this library. I've started thinking a bit more about dealing with arbitrary properties here #145 but not sure yet how I will deal with that. Changing a type to |
Obtaining the actual response form is useful. I need to use the |
hey @evert, any update on extra parameters or the |
No update. I will get to it when I can. In the meantime you can:
if you're in a hurry 1) is probably the quickest, and you can just remove that again when this is changed in a future release. |
By default Github will return urlencoded data when doing requests on the token endpoint. Setting this accept header ensures we're getting JSON back. This is non-standard, but there's no harm. See #151
When working with GitHub OAuth2, everything seems to work fine initially. However, when the auth server redirects to the client callback, an error is thrown indicating:
TypeError: Cannot read properties of undefined (reading 'access_token')
. I tested it with other libraries, such assimple-oauth2
, and it works fine. This issue appears to be related tooauth2-client
and seems to be a bug that needs to be fixed.The text was updated successfully, but these errors were encountered: