Skip to content

Comments

use 401 for expired or malformed tokens#23

Merged
timbod7 merged 2 commits intoadl-lang:masterfrom
alexytsu:unauthorized-error
Apr 15, 2025
Merged

use 401 for expired or malformed tokens#23
timbod7 merged 2 commits intoadl-lang:masterfrom
alexytsu:unauthorized-error

Conversation

@alexytsu
Copy link
Contributor

Allows frontend to use 401 as a trigger for requesting new token or prompting user to login.
403s suggest developer error in frontend, i.e. the app should not allow users to hit endpoints they don't have the right role for.

whilst this weakens the "all requests are 200, errors are checked in userland" rule, it would be handled once centrally in an app.

Copy link
Contributor

@timbod7 timbod7 left a comment

Choose a reason for hiding this comment

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

modulo the comment I'm fine with this change it seems to match the http spec better.

But I fail to see how why this is important:

Allows frontend to use 401 as a trigger for requesting new token or prompting user to login.

as I think the existing approach where the token is refreshed prior to expiring is prefereable:

it seems unfortunate that we've lost this behaviour in the ts/ui/ code. On cloning for a new project the first thing I'd do would be to copy ts/api-workbench/src/hooks/use-app-state.ts into ts/ui/ for the auth and referesh behaviour.

@@ -199,7 +199,7 @@ fn claims_from_bearer_token(
let jwt = jwt::bearer_token_from_auth_header(auth_header).ok_or(forbidden())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be unauthorized() also?

@timbod7 timbod7 merged commit 3e7e36c into adl-lang:master Apr 15, 2025
2 checks passed
@alexytsu alexytsu deleted the unauthorized-error branch April 16, 2025 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants