Skip to content
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

Implemented the oauth2 integration between FastAPI and Authlib #278

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

gmachado-nextreason
Copy link

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

  • You consent that the copyright of your pull request source code belongs to Authlib's author.

@gmachado-nextreason
Copy link
Author

This is an example of OpenID Connect 1.0 server in FastAPI and Authlib.

https://github.com/gmachado-nextreason/example-oidc-server-fastapi

@lepture
Copy link
Owner

lepture commented Oct 9, 2020

It is impossible to implement FastAPI OAuth providers for now. Because FastAPI is async, Authlib is not ready for async providers. This should be done in v2.0.

@lepture lepture closed this Oct 9, 2020
@gmachado-nextreason
Copy link
Author

Thanks for quick review @lepture.

Although FastAPI supports third party non async libraries:
fastapi/fastapi#260
https://fastapi.tiangolo.com/async/

"If you are using a third party library that communicates with something (a database, an API, the file system, etc) and doesn't have support for using await, (this is currently the case for most database libraries), then declare your path operation functions as normally, with just def"

As you can see on the routes.py example, I created all the endpoints without async:
https://github.com/gmachado-nextreason/example-oidc-server-fastapi/blob/master/src/routes.py

This is just a proposed integration solution between FastAPI and Authlib without async. I'm aware authlib only supports async for client not server yet (#63), just wanted to provide more options if anyone else is interested. Please let me know if it is still not the case. Glad to help anyhow.

@lepture lepture reopened this Oct 10, 2020
@lepture
Copy link
Owner

lepture commented Oct 10, 2020

@gmachado-nextreason Yes, you are correct. We can support sync mode at first. But I won't add it in v0.15, how about adding it to v1.0.

There are still works to do:

  • Adding test cases
  • Remove the deprecated code

@gmachado-nextreason
Copy link
Author

Removed deprecated code and added the test cases scenarios.

@lepture can you please review it again once you have a chance?

"""Implementation of authlib.oauth2.rfc6749.AuthorizationServer class for FastAPI."""

import json
from werkzeug.utils import import_string
Copy link
Owner

Choose a reason for hiding this comment

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

It is not a good idea to import werkzeug for FastAPI.

@lepture
Copy link
Owner

lepture commented Nov 13, 2020

I'll merge and refactor the code later. I'm working on other stuff right now.

@gmachado-nextreason
Copy link
Author

@lepture resolved the conflict on tox.ini file, it is ready for you to merge. Thank you.

@seweissman
Copy link

Will this be merged? I'm interested in using/contributing to this.

@synchronizing
Copy link

Any updates on this PR? FastAPI integration (sync or async) would be a nice addon.

@lepture lepture added the hold on label Mar 5, 2021
@lepture
Copy link
Owner

lepture commented Mar 5, 2021

I'm not sure if this will get merged. I would like to make it a separate package since I have a plan to move Flask and Django integrations into separate packages in v2.0.

For FastAPI, it is better to support async mode, but currently Authlib only has sync mode. I'll make it async in v2.0 too.

In this case, I wonder if it is a good idea to have this PR (FastAPI) as built-in OAuth provider.

@synchronizing
Copy link

@lepture Roger that. There is current work over at aioauth to bring OAuth to the async world. I'm one of the contributors over there, and if you have any recommendations/tips - or would like to contribute on it yourself - that would be greatly appreciated.

@toxadx
Copy link

toxadx commented Oct 18, 2021

It is better to focus not on FastAPI support, but on Starlette, because FastAPI is based on Starlette.

@limness
Copy link

limness commented Jul 31, 2024

Hey! Still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants