SQLpage icon indicating copy to clipboard operation
SQLpage copied to clipboard

Native support for JWT

Open rdelaage opened this issue 10 months ago • 3 comments

What are you building with SQLPage ?

A proof of concept for use as a general purpose engine for declarative apps

What is your problem ? A description of the problem, not the solution you are proposing.

I would like to manage sessions for users with a stateless solution

What are you currently doing ? Since your solution is not implemented in SQLPage currently, what are you doing instead ?

JWT or PHP sessions

Describe the solution you'd like

Provide two built-in functions (like in this project https://github.com/michelp/pgjwt):

  • sqlpage_jwt_sign(payload: json_str, secret: str) -> str provides a JWT signed using the provided secret
  • sqlpage_jwt_verify(jwt_token: str, secret: str) -> |header: json_str|payload: json_str|valid: bool| verifies that the provided JWT and gives the payload and the header

Describe alternatives you've considered

Using https://github.com/michelp/pgjwt

Additional context

rdelaage avatar Feb 20 '25 12:02 rdelaage

Hello, and thank you for getting in touch ! This sounds very interesting ! Could you open a pull request ?

lovasoa avatar Feb 23 '25 00:02 lovasoa

Hello, I'm glad you find this interesting. I would be pleased to open a pull request. I have never programmed in Rust but if you give me some time I could try to draft something. Could you give me some pointers of which parts of the program to modify to add functions?

rdelaage avatar Feb 24 '25 09:02 rdelaage

Sure ! We have a contribution guide here : Don't hesitate to ping me if anything sounds unclear or too complex, I'll be happy to help !

For this particular issue, I think what you will be the most interested in is: https://github.com/sqlpage/SQLPage/blob/main/examples/official-site/functions.sql. You can declare new sqlpage functions entirely from that file.

For manipulating the jwt themselves, you can add https://crates.io/crates/jwt-simple to the dependencies

lovasoa avatar Feb 24 '25 09:02 lovasoa