# Unable to exchange token during in-client oauth flow (and other issues)

**URL:** <https://devforum.zoom.us/t/unable-to-exchange-token-during-in-client-oauth-flow-and-other-issues/77933>\
**Category:** Zoom Apps\
**Tags:** oauth\
**Created:** [October 26, 2022, 4:07pm UTC](https://devforum.zoom.us/t/unable-to-exchange-token-during-in-client-oauth-flow-and-other-issues/77933 "2022-10-26T16:07:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![seshandrew](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/seshandrew/32/33489_2.png) [@seshandrew](https://devforum.zoom.us/u/seshandrew)\
**Post date:** [October 26, 2022, 4:07pm UTC](https://devforum.zoom.us/t/unable-to-exchange-token-during-in-client-oauth-flow-and-other-issues/77933/1 "2022-10-26T16:07:31Z")

</div>

we’re having some real issues implementing in-app auth.

1. Key exchange after authorize isn’t working — each time it’s giving us a `{"reason":"Invalid authorization code XXXXX”,”error":"invalid_grant”}` error — whether we use curl or our backend using the code we get back from `onAuthorized()`. We’ve tried using our go code and the example JS code to generate the challenge.
2. Should we be calling authorize() at app startup each time? If we attempt to install from the ‘guest mode’ window chrome we’re not getting any onMyUserContextChanged() events.
3. Using promptAuthorize() to upgrade from guest mode to authorized likewise doesn’t trigger any onMyUserContextChanged() events. We don’t have any visibility that the permissions have changed.

We have promptAuthorize(), authorize(), getUserContext(), onAuthorized and onMyUserContextChange enabled and configured.

```auto
curl --request POST \
--url https://zoom.us/oauth/token \
--header 'Content-type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic BASE_64_ENCODED(CLIENT_ID:SECRET)' \
--data code=CODE_FROM_ON_AUTHORIZE \
--data code_verifier=ORIGINAL_CODE_VERIFIER \
--data grant_type=authorization_code \
--data redirect_uri=HREF_WHERE_AUTHORIZE_WAS_CALLED

```

On a separate note – the zoom client doesn’t clear the cookies when you remove an installed app using the marketplace – we can code aroudn this but it seems like it’s a security issue.  
Repro:

- Open an installed app in a meeting
- Create a cookie on app open
- Invite users in the meeting to use the app
- Remove the app from the marketplace
- The app pane closes
- Open the old invitation
- The app opens in guest mode
- The cookie (tied to the former, installed session) is still present.

---

<div class="post-metadata">

**Author:** ![ash.provost](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ash.provost/32/36610_2.png) [@ash.provost](https://devforum.zoom.us/u/ash.provost)\
**Post date:** [October 26, 2022, 6:30pm UTC](https://devforum.zoom.us/t/unable-to-exchange-token-during-in-client-oauth-flow-and-other-issues/77933/2 "2022-10-26T18:30:32Z")

</div>

The error you’re seeing has to do with your oauth against the [zoom.us](http://zoom.us/) oauth endpoints. There are severable searchable posts on the forum on this issue. Here is one of them: [Cannot renew access and refresh token (invalid\_grant)](https://devforum.zoom.us/t/cannot-renew-access-and-refresh-token-invalid-grant/75224)

The docs on OAuth with Zoom are here: [OAuth with Zoom](https://developers.zoom.us/docs/guides/auth/oauth)

---

<div class="post-metadata">

**Author:** ![seshandrew](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/seshandrew/32/33489_2.png) [@seshandrew](https://devforum.zoom.us/u/seshandrew)\
**Post date:** [October 26, 2022, 6:53pm UTC](https://devforum.zoom.us/t/unable-to-exchange-token-during-in-client-oauth-flow-and-other-issues/77933/3 "2022-10-26T18:53:42Z")

</div>

If I manually create an authorization URL in the browser (with the same code challenge) and curl the exchange with the given code, it works.

If I use the same code challenge using authorize, the code that authorize returns fails.

If this is a “you need to use a refresh token” issue, what happens when/if our zoom refresh token isn’t persisted? The docs (including the example app) indicate that you need to use authenticate() to get a new token.

---

<div class="post-metadata">

**Author:** ![ash.provost](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ash.provost/32/36610_2.png) [@ash.provost](https://devforum.zoom.us/u/ash.provost)\
**Post date:** [October 26, 2022, 7:10pm UTC](https://devforum.zoom.us/t/unable-to-exchange-token-during-in-client-oauth-flow-and-other-issues/77933/4 "2022-10-26T19:10:13Z")

</div>

As for the `onMyUserContextChange` event trigger, promptAuthorize should trigger this since client version `5.12.0`. What client version are you on?

We created a bug ticket for the cookie clearing issue, will report to appropriate internal team.

---

<div class="post-metadata">

**Author:** ![ash.provost](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ash.provost/32/36610_2.png) [@ash.provost](https://devforum.zoom.us/u/ash.provost)\
**Post date:** [October 26, 2022, 7:28pm UTC](https://devforum.zoom.us/t/unable-to-exchange-token-during-in-client-oauth-flow-and-other-issues/77933/5 "2022-10-26T19:28:31Z")

</div>

Are you using the `plain` or `S256` for setting the code\_challenge? if you are using `S256`, would you test `plain`?

---

<div class="post-metadata">

**Author:** ![seshandrew](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/seshandrew/32/33489_2.png) [@seshandrew](https://devforum.zoom.us/u/seshandrew)\
**Post date:** [October 26, 2022, 8:26pm UTC](https://devforum.zoom.us/t/unable-to-exchange-token-during-in-client-oauth-flow-and-other-issues/77933/6 "2022-10-26T20:26:27Z")

</div>

Ah ha! It was 5.11.6! Hopefully the new client will fix the issues…

---

<div class="post-metadata">

**Author:** ![seshandrew](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/seshandrew/32/33489_2.png) [@seshandrew](https://devforum.zoom.us/u/seshandrew)\
**Post date:** [October 26, 2022, 10:45pm UTC](https://devforum.zoom.us/t/unable-to-exchange-token-during-in-client-oauth-flow-and-other-issues/77933/7 "2022-10-26T22:45:09Z")

</div>

I’m using S256 when I manually create the URL (to generate a code that works). The challenge type isn’t a parameter in the authorize() call ([Zoom Apps JS SDK reference](https://marketplace.zoom.us/docs/zoom-apps/js-sdk/reference/#authorize))-- could the authorize be omitting that behind the scenes?

---

<div class="post-metadata">

**Author:** ![seshandrew](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/seshandrew/32/33489_2.png) [@seshandrew](https://devforum.zoom.us/u/seshandrew)\
**Post date:** [October 26, 2022, 10:45pm UTC](https://devforum.zoom.us/t/unable-to-exchange-token-during-in-client-oauth-flow-and-other-issues/77933/8 "2022-10-26T22:45:44Z")

</div>

Updating the client fixed the oncontextchange events (but not the oauth problem)

---

<div class="post-metadata">

**Author:** ![seshandrew](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/seshandrew/32/33489_2.png) [@seshandrew](https://devforum.zoom.us/u/seshandrew)\
**Post date:** [October 26, 2022, 11:17pm UTC](https://devforum.zoom.us/t/unable-to-exchange-token-during-in-client-oauth-flow-and-other-issues/77933/9 "2022-10-26T23:17:19Z")

</div>

😑

The issue was that the codeChallenge we were providing to `authorize()` was _not_ in plaintext – the [docs](https://marketplace.zoom.us/docs/zoom-apps/guides/authentication/#enabling-in-client-oauth-for-your-app) explicitly say only S256 is supported! Could this be an SDK version issue?

---

<div class="post-metadata">

**Author:** ![ash.provost](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ash.provost/32/36610_2.png) [@ash.provost](https://devforum.zoom.us/u/ash.provost)\
**Post date:** [October 26, 2022, 11:19pm UTC](https://devforum.zoom.us/t/unable-to-exchange-token-during-in-client-oauth-flow-and-other-issues/77933/10 "2022-10-26T23:19:28Z")

</div>

The documentation is incorrect. The client does not officially support the `S256` codeChallenge, only `plain` at this time. We will create a bug ticket to resolve this issue.
