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

Switch to JWT based auth #48

Merged
merged 7 commits into from
Aug 23, 2020
Merged

Switch to JWT based auth #48

merged 7 commits into from
Aug 23, 2020

Conversation

Empty2k12
Copy link
Contributor

@Empty2k12 Empty2k12 commented Aug 21, 2020

In preparation for supporting smart-locks, whose API is only available in JWT based routes.

@NeoLegends
Copy link
Owner

NeoLegends commented Aug 21, 2020

I like this! Perhaps the fetch-wrapping methods could catch the timeouted token, and then transparently do a refresh and retry the fetch. I think this would be the best way. It would just cause some additional delay here and there, but that would be it.

I think we use the isAuthed check to determine whether to show the users the account pages or whether to show a login form there.

@NeoLegends NeoLegends added the enhancement New feature or request label Aug 21, 2020
@Empty2k12 Empty2k12 marked this pull request as draft August 22, 2020 19:09
@Empty2k12 Empty2k12 marked this pull request as ready for review August 22, 2020 19:19
Copy link
Owner

@NeoLegends NeoLegends left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the work! I have some small nits.

@@ -62,11 +60,7 @@ const MenuBar: React.FC<MenuBarProps> = ({
</button>

<button className="btn outline" onClick={onLoginButtonClick}>
{loginStatusKnown
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that we always synchronously know the login state now.

src/model/authentication.ts Outdated Show resolved Hide resolved
Comment on lines 36 to 37
const url = hasTokens() ? JWT_ALL_STATIONS_URL : APP_ALL_STATIONS_URL;
return fetchJsonEnsureOk(url, undefined, 5, hasTokens()).then((stations) =>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why we need to use both URLs here? I think these endpoints don't provide user-specific data and thus don't require auth. So I think we don't ever need to use the JWT routes here and we can remove this complexity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is complexity, but there might be additional information available in authed routes in the future, which would mean this change would be relevant.

Another point is, now Velocity knows which user has requested the data, with possible exemptions from rate limiting or other preferential request handling. If and when such measures might be implemented by Velocity is questionable, but this would future-proof the application for such changes.

Copy link
Owner

@NeoLegends NeoLegends Aug 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For authed routes I would like to provide a second function, however, such that the guarantees are clear and you know exactly which data the function will be giving you. And, in their API they very clearly separated authed routes from unauthed routes, and make you do the matching itself (stations endpoint gives data you can use with the booking endpoint, for example).

And in regards to the rate-limiting: While theoretically yes, I doubt Velocity will take the user accounts into account for any rate-limiting they do. I doubt they even rate-limit at all from my past experiences. So I'd prefer to remove this complexity and change in behavior that's dependent on global state from the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the default behaviour back to using unauthenticated routes, and provided functions which call the authenticated counterparts for use in the future.

src/model/stations.ts Outdated Show resolved Hide resolved
src/model/stations.ts Outdated Show resolved Hide resolved
@NeoLegends NeoLegends assigned NeoLegends and Empty2k12 and unassigned NeoLegends Aug 22, 2020
@NeoLegends NeoLegends changed the title 👽 Switch to JWT based auth Switch to JWT based auth Aug 22, 2020
src/model/stations.ts Outdated Show resolved Hide resolved
@NeoLegends NeoLegends merged commit 8718443 into NeoLegends:master Aug 23, 2020
@Empty2k12 Empty2k12 deleted the feature/use-jwt-auth branch August 23, 2020 13:56
@Empty2k12 Empty2k12 mentioned this pull request Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants