supertokens-python icon indicating copy to clipboard operation
supertokens-python copied to clipboard

Support LiteStar

Open Goldziher opened this issue 2 years ago • 13 comments

Hi there,

I'm one of the maintainers of Litestar. We received a request to add support for supertokens -> https://github.com/litestar-org/litestar/issues/1497. I'm willing to put up a PR for this in this repository, is this something you would be interested in?

Goldziher avatar Apr 15 '23 06:04 Goldziher

hey @Goldziher we are open to a PR. You would need to add Litestar as a framework just like how we have added flask (and others) as a framework: https://github.com/supertokens/supertokens-python/tree/master/supertokens_python/framework/flask

  • A litestar middleware: This would be responsible for calling the supertokens middleware which would handle API calls like sign up / sign in etc.. The middleware also needs to handle supertokens specific errors.
  • A request / response implementation that conforms to the BaseRequest and BaseResponse interfaces.
  • Finally, a version of the verify_session function which can be used to protect a user's API. Here is an example for flask: https://github.com/supertokens/supertokens-python/blob/master/supertokens_python/recipe/session/framework/flask/init.py

rishabhpoddar avatar Apr 15 '23 06:04 rishabhpoddar

PR has been added @rishabhpoddar. I cannot make the tests pass locally - due to some issues with the testing setup (see my comment in the PR description).

Frankly this testing setup is a bit too complex for my brain. I cannot debug this because the error seems to be in the root repo(?).

The code I added is clean and it should be pretty close to so done.

It would be great if you guys take this from this point onwards since you understand what is happening here and I don't.

As an aside - I would suggest you guys switch your setup for tooling to using pre-commit, mypy and ruff + a package manager that uses pyproject.toml such as poetry.

You can see a good example of this in the litestar repository, and im sure there are plenty of people who would love to contribute this for you guys (I know a few on our discord server). Feel free to join our server if you want assistance with this stuff or anything else.

I'll be around to assist in what I can - I hope this PR moves forward.

Goldziher avatar Apr 15 '23 13:04 Goldziher

Nice job! I hope this PR goes through as i would like to use Supertokens and litestar in some of my projects!

Spectryx avatar Apr 16 '23 07:04 Spectryx

@Spectryx we will be reviewing the PR shortly, but until then, you could use the forked version of the SDK to test it out and see if you run into any issues (which will also help us with testing / reviewing). Thanks

rishabhpoddar avatar Apr 16 '23 15:04 rishabhpoddar

@rishabhpoddar Hi! Sure, i'll try to get it up and running with litestar later today and see how it goes!

Spectryx avatar Apr 17 '23 12:04 Spectryx

I cant get it to work, see this comment https://github.com/supertokens/supertokens-python/pull/311#issuecomment-1513759899

Spectryx avatar Apr 18 '23 20:04 Spectryx

I guess the attempt to include Litestar has been aborted? :(

ctrl-Felix avatar Nov 11 '23 11:11 ctrl-Felix

im out of the equation in litestar - you guys should reach out to the maintainers on discord to get support for this.

Goldziher avatar Nov 11 '23 11:11 Goldziher

We are still happy to accept the PR for Litestar if someone can work on it.

rishabhpoddar avatar Nov 11 '23 13:11 rishabhpoddar

I took the work from https://github.com/supertokens/supertokens-python/pull/311 and put it into a new one: https://github.com/supertokens/supertokens-python/pull/483

I didn't get the test to working, as litestar is expecting at least python 3.8 and the test environment seems to use 3.7. any chance to update the test container?

0asys avatar Apr 08 '24 21:04 0asys

any chance to update the test container?

We can update this once we are at the phase of CICD testing. You can test it locally with 3.8 python though

rishabhpoddar avatar Apr 09 '24 05:04 rishabhpoddar