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

[FIX] Custom Oauth store refresh and id tokens with expiresIn #14121

Merged
merged 7 commits into from
Apr 16, 2019
Merged

[FIX] Custom Oauth store refresh and id tokens with expiresIn #14121

merged 7 commits into from
Apr 16, 2019

Conversation

ralfbecker
Copy link
Contributor

@ralfbecker ralfbecker commented Apr 12, 2019

Closes #13693

@CLAassistant
Copy link

CLAassistant commented Apr 12, 2019

CLA assistant check
All committers have signed the CLA.

@ralfbecker
Copy link
Contributor Author

ralfbecker commented Apr 12, 2019

@geekgonecrazy do you mind reviewing this

@geekgonecrazy
Copy link
Member

Nice! I’m not sure however... if the refresh is ever even used?

@ralfbecker
Copy link
Contributor Author

The ci/circleci test failures have nothing to do with this pull-request:

WARNING: The following packages cannot be authenticated!
  google-chrome-stable
E: There were unauthenticated packages and -y was used without --allow-unauthenticated

@ralfbecker
Copy link
Contributor Author

@geekgonecrazy You mean if Rocket.Chat/Meteor uses refreshTokens, or that it need to be set in a different way? I'm setting it now, like the Google provider sets it.

Ralf

@geekgonecrazy
Copy link
Member

geekgonecrazy commented Apr 12, 2019

No I mean. Now we have it.. cool! but where or how is the refresh token actually used by Rocket.Chat?

@ralfbecker
Copy link
Contributor Author

The accessToken is registered with it's expiration. If we got an refreshToken, we can use that to get a new accessToken, after it's expired, without "bugging" the user again.
My expectation is that this is done in Meteor's or Rocket.Chat's existing OAuth code. Why else would the other providers register the refreshToken. I have not verified that!

Ralf

@geekgonecrazy
Copy link
Member

Just a heads up by adding the registerAccessToken as part of this you have overlap with: #14113 opened just a bit before yours.

@ralfbecker
Copy link
Contributor Author

Hmm, #14113 seems to do the same as my intended next pull request:
63f6e52

@ralfbecker
Copy link
Contributor Author

I rebased this pull request in my repo on top of @knrt10 one: https://github.com/EGroupware/Rocket.Chat/commit/7aba9cad805d376aaef2c7a7e6901bc742df00ad

I searched through Rocket.Chat codebase for usage of expiresAt or refreshToken: I'm pretty sure they are NOT used at all :(

I think when Rocket.Chat receives an accessToken, eg. through custom OAuth, it's ok to verify it's currently valid by using the identity endpoint with the accessToken as Authorization: Bearer.
Rocket.Chat then stores, with this pull request, expiresAt and, if we receive one, the refreshToken.

When the next Api request with the same token arrives, you can either:
a) check it again with the identity endpoint or
b) check the stored expiresAt time and only re-check if it's past that time
So for Api access there is (only) less latency to again, refresh token does not help at all.

Other use case is the Rocket.Chat client and I believe that's what #13693 is talking about: after the initial OAuth authentication by the user, Rocket.Chat should not assume the user is authenticated for ever, but only for the lifetime of the token. If the token is expired, Rocket.Chat either needs to bug the user again for an other OAuth authentication, or try to automatically get a new accessToken through the refreshToken (from the server-side), which might fail in case the user revoked the refreshToken in the meantime because he eg. lost the device.

I think that's were Rocket.Chat has a problem: there is no way to cut off access by a lost client-device, in case an external OAuth server is used.

Ralf

@geekgonecrazy
Copy link
Member

Seems you are at the same conclusion I reached.

I still think this is great to have added. But yes we may need to follow up with a pull request to tie rocket.chat token life time to oauth life time. But I have a feeling that will not be an easy task to track down

geekgonecrazy
geekgonecrazy previously approved these changes Apr 13, 2019
@geekgonecrazy geekgonecrazy changed the title [FIX] Custom Oauth does not register the refreshToken nor respect the accessToken lifetime [FIX] Custom Oauth does not keep the refreshToken or idToken Apr 13, 2019
@geekgonecrazy geekgonecrazy changed the title [FIX] Custom Oauth does not keep the refreshToken or idToken [FIX] Custom Oauth store refresh and id tokens with expiresIn Apr 13, 2019
@geekgonecrazy
Copy link
Member

Sorry some of these suggestions are only needed because of the conflict merging. 😊

geekgonecrazy and others added 3 commits April 16, 2019 09:06
Co-Authored-By: ralfbecker <rb@egroupware.org>
Co-Authored-By: ralfbecker <rb@egroupware.org>
Co-Authored-By: ralfbecker <rb@egroupware.org>
geekgonecrazy
geekgonecrazy previously approved these changes Apr 16, 2019
@rodrigok rodrigok merged commit b643dcb into RocketChat:develop Apr 16, 2019
@rodrigok rodrigok mentioned this pull request Apr 28, 2019
@weand
Copy link

weand commented May 20, 2020

Seems you are at the same conclusion I reached.

I still think this is great to have added. But yes we may need to follow up with a pull request to tie rocket.chat token life time to oauth life time. But I have a feeling that will not be an easy task to track down

is there any issue available thats tracks progress for "pull request to tie rocket.chat token life time to oauth life time"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Custom Oauth does not register the refreshToken nor respect the accessToken lifetime.
5 participants