Skip to content
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

User.getUserOauthAccessToken has the wrong return type #447

Closed
5 of 15 tasks
emmiep opened this issue Oct 19, 2022 · 2 comments · Fixed by #528
Closed
5 of 15 tasks

User.getUserOauthAccessToken has the wrong return type #447

emmiep opened this issue Oct 19, 2022 · 2 comments · Fixed by #528

Comments

@emmiep
Copy link

emmiep commented Oct 19, 2022

Package + Version

  • @clerk/clerk-js
  • @clerk/clerk-react
  • @clerk/nextjs
  • @clerk/remix
  • @clerk/types
  • @clerk/themes
  • @clerk/clerk-expo
  • @clerk/backend-core 2.9.1
  • @clerk/clerk-sdk-node
  • @clerk/edge
  • other:

Version:

2.9.1

Browser/OS

Not applicable

Description

It seems like the method getUserOauthAccessToken in the class UserAPI has the wrong return type: https://github.com/clerkinc/javascript/blob/250a47daf561928e7d09b48873b19be4de28a581/packages/backend-core/src/api/endpoints/UserApi.ts#L120
The method returns the return value from this.APIClient.request<User>, which makes the return type Promise<User>, and this doesn't seem correct given the name of the function, the backend API docs and the return data from the API.
The User type doesn't match the data returned from the method:

https://github.com/clerkinc/javascript/blob/250a47daf561928e7d09b48873b19be4de28a581/packages/backend-core/src/api/resources/User.ts#L7

From the method body it seems like it calls the /v1/users/:id/oauth_access_tokens/:provider endpoint of the backend API, which does makes sense.
However, in the backend documentation the data from this endpoint is an array of objects with the "object" property having the value "oauth_access_token", which obviously doesn't matches the User type:

https://reference.clerk.dev/reference/backend-api-reference/users#retrieve-the-oauth-access-token-of-a-user

Here's the example return value:

[
  {
    "object": "oauth_access_token",
    "provider": "oauth_google",
    "token": "xxxxxxxxxxxxxxxxxxxxx",
    "public_metadata": {},
    "label": "clerk",
    "scopes": [
      "openid",
      "https://www.googleapis.com/auth/userinfo.email"
      "https://www.googleapis.com/auth/userinfo.profile"
    ]
  }
  ...
]

When calling the function, I get a similar JSON object as well:

[
  {
    "object": "oauth_access_token",
    "token": "",
    "provider": "oauth_notion",
    "public_metadata": {
      "bot_id": "",
      "workspace_id": "",
      "workspace_icon": "",
      "workspace_name": ""
    },
    "label": ""
  }
]

I can't find a type in the JS API matching this type, for instance no object with this object type can be found in the ObjectType enum:

https://github.com/clerkinc/javascript/blob/250a47daf561928e7d09b48873b19be4de28a581/packages/backend-core/src/api/resources/JSON.ts#L12

Nor do I find the string oauth_access_token in the entire repo:

https://github.com/clerkinc/javascript/search?q=oauth_access_token

It seems like there's missing an OAuthAccessToken and its companion OAuthAccessTokenJSON type, and the UserAPI.getUserOauthAccessToken method should return Promise<OAuthAccessToken[]> rather than Promise<User>.

@jasonkuhrt
Copy link

Is there any particular reason this is taking "so long" to get resolved?

@SokratisVidros
Copy link
Contributor

Thanks for bringing this to our attention. We will push a fix ASAP.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants