javascript icon indicating copy to clipboard operation
javascript copied to clipboard

User.getUserOauthAccessToken has the wrong return type

Open emmiep opened this issue 3 years ago • 0 comments

  • [x] Review the documentation: https://docs.clerk.dev/
  • [x] Search for existing issues: https://github.com/clerkinc/javascript/issues
  • [x] Go through package changelog files.
  • [x] ~~Provide the Frontend API key from your application dashboard.~~ not applicable

Package + Version

  • [ ] @clerk/clerk-js
  • [ ] @clerk/clerk-react
  • [ ] @clerk/nextjs
  • [ ] @clerk/remix
  • [ ] @clerk/types
  • [ ] @clerk/themes
  • [ ] @clerk/clerk-expo
  • [x] @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>.

emmiep avatar Oct 19 '22 12:10 emmiep