roc-lang / basic-webserver

A basic webserver in Roc
https://roc-lang.github.io/basic-webserver/
Universal Permissive License v1.0
72 stars 15 forks source link

Add support for Json Web Token verification #72

Open lukewilliamboswell opened 4 weeks ago

lukewilliamboswell commented 4 weeks ago

Based on builtin-task so most of these commits should merge (hopefully) and disappear.

lukewilliamboswell commented 4 weeks ago

Implementation is good to go with 3/12 algorithms implemented and the example working ok. It's mostly a matter of copy-paste to include the other algorithms, but we can do this later.

There is a lurking Error in alias analysis issue which I think blocks this PR as it's too easy to hit.

test case

# Test Hs256 algorithm
result = Jwt.verify! {
    secret: "shhh_very_secret",
    algorithm: Hs256,
    token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.joReqPNNkWQ8zQCW3UQnhc_5NMrSZEOQYpk6sDS6Y-o",
}

demo

Screenshot 2024-08-30 at 16 59 11