-
Notifications
You must be signed in to change notification settings - Fork 115
Parse unverified JWT #756
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
Parse unverified JWT #756
Conversation
|
@1egoman I'm thinking of removing JWTKit dependency in Swift, what else do you need for JS - something like: pub fn with_unverified_options(
token: &str,
validate_exp: bool,
validate_nbf: bool,
leeway: Option<Duration>,
) -> Result<Self, AccessTokenError> |
|
@pblazej I think the As an unrelated FYI, I actually implemented some quite similar logic here but I like the way you did it here better, so I'll just use this interface instead once this one is merged. |
livekit-api/src/access_token.rs
Outdated
|
|
||
| #[test] | ||
| fn test_unverified_token() { | ||
| let claims = Claims::with_unverified(TEST_TOKEN).expect("Failed to parse token"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, it would be good to have a 2 other tests:
- Try parse a token that was valid in the past but no longer is valid, and make sure it fails
- Try to parse a token which will become valid in the future and make sure it fails
Yeah, I realized after a while it must be duplicated 😃
Yes, I struggled a bit with custom types there, but may be worth doing
Is that I'll update this PR in spare time 👍 If the token source goes merged first, feel free to close it/use it somehow. |
ladvoc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ✅
livekit-uniffi/src/access_token.rs
Outdated
| /// WARNING: Do not use this for authentication - the signature is not verified! | ||
| /// | ||
| #[uniffi::export] | ||
| pub fn unverified_token(token: &str) -> Result<Claims, AccessTokenError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Not specific to this PR, but in Swift, symbols will be imported in the global namespace, right? If so, we might consider using a standardized naming scheme for exported symbols from each module. For example, in this module we would have token_claims_from_unverified (this method), token_verify, and token_generate—everything is prefixed with "token" so it is clear which module it comes from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep I wanted to ask that in Notion actually, it's not possible to create something like Claims.myNewMethod at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ I've only played around with the python bindings, but at least with those I was able to export a class as an "object" with static methods (I think I had to mark them technically as "alternate constructors") and that seemed to work. But maybe the swift bindings are different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied the token_ prefix, I don't think we can do more about namespaces (am I wrong?)
e584ecb to
9d9cdb3
Compare
|
I managed to replace the Swift JWT logic: https://github.com/livekit/client-sdk-swift/pull/822/files The only (async) question is shall we expose these objects like |
472f566 to
6498164
Compare
|
I'm merging that into the main |
Enables "caching token source" on the client without 3rd party dependencies.