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

Refactor and new features #25

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

Conversation

samedii
Copy link
Contributor

@samedii samedii commented Sep 13, 2021

  • Select grant flows for docs
  • Granular optional auth for endpoints with auth.required and auth.optional
  • Granular scope verification with Security instead of Depends
  • Slightly more transparent argument names
  • Follow openid connect specification for verification more closely
  • Github action for publishing (requires a pypi token in github secrets)

@samedii samedii force-pushed the interface branch 5 times, most recently from ec72af7 to 392eccb Compare September 13, 2021 17:08
@HarryMWinters
Copy link
Owner

HarryMWinters commented Sep 14, 2021

Hey @samedii.

Your code is good. It's better than what I wrote in most ways. But you have a 600+ line PR in repo whose source code was a third that size. And your changes are breaking the modules API.

So I have to ask, why use this package at all? Why not just publish your own?

EDIT: It probably is worth getting into this library so there are not two options floating around. We'll just have to cut a 1.0.0 release for all the breaking changes. The smaller we can keep the PRs the easier it's going to be for me to be able to make time to review them.

@samedii
Copy link
Contributor Author

samedii commented Sep 14, 2021

Yes if you don't want to merge this then I will have to publish another. There are already a lot of alternative packages on pypi (that don't have working docs)

Breaking this up into many small PRs will be extremely time consuming. I'll probably temporarily publish and then you can have a look at the total. If you want to merge then we can do cleanup/rewrites however you prefer

@HarryMWinters
Copy link
Owner

Well, let me know when the branch is ready for review and I'll go over it when I can. I'm not at to ReadTheDocs btw if you've got a preference for something else.

@samedii
Copy link
Contributor Author

samedii commented Sep 14, 2021

I'll probably make minor cleanups and doc changes but it's largely done now.

Do you have a use case for having another audience than client id?

This is from the specs:

REQUIRED. Audience(s) that this ID Token is intended for. It MUST contain the OAuth 2.0 client_id of the Relying Party as an audience value. It MAY also contain identifiers for other audiences. In the general case, the aud value is an array of case sensitive strings. In the common special case when there is one audience, the aud value MAY be a single case sensitive string.

I removed audience and just have client_id now. I'm thinking that if someone wants to require an extra audience then they can validate that with a custom IDToken model

@samedii samedii changed the title Interface Refactor and new features Sep 14, 2021
Copy link
Owner

@HarryMWinters HarryMWinters left a comment

Choose a reason for hiding this comment

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

It looks really good @samedii! I left some comments but I hope they serve as a conversation starter more than explicit change requests. They fall into a couple of broad categories:

  1. Subclassing FastAPI errors.
  2. Type annotations (can we make them dynamic? Could be tricky).
  3. Security vs. Depends.
  4. Authorship and ownership. I hope you'll consider adding your name to the authors and becoming a maintainer.

Thanks for your patience while I got to this.

.github/workflows/publish.yaml Outdated Show resolved Hide resolved
.github/workflows/publish.yaml Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
docs/index.rst Show resolved Hide resolved
fastapi_oidc/auth.py Show resolved Hide resolved
fastapi_oidc/auth.py Outdated Show resolved Hide resolved

except (ExpiredSignatureError, JWTError, JWTClaimsError) as err:
raise HTTPException(status_code=401, detail=f"Unauthorized: {err}")
Copy link
Owner

Choose a reason for hiding this comment

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

What do you think about subclassing HTTPException? It would make it easier and more explicit to catch exceptions from this library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like a good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you have a look at this since you seem to know what you would like to have? @HarryMWinters

pyproject.toml Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@samedii
Copy link
Contributor Author

samedii commented Sep 22, 2021

I tried to get everything in here before publishing fastapi-third-party-auth but there are some issues that I found after doing the renaming. I can probably resolve this by doing some cherry picking / rebasing

@HarryMWinters
Copy link
Owner

@samedii I think there's a few unresolved comments but nothing that should take very long. I'm happy to take on some of the work or I'm sure you could wrap it up quickly if you have time.

Once this is merged I'm going to play around a bit with the tagging workflow but I imagine we should be able to publish quickly.

Anyways, let me know what you think.

Cheers

@HarryMWinters
Copy link
Owner

Bump @samedii Are you still interested in merging this? Or would it be better if I took it over?

@samedii
Copy link
Contributor Author

samedii commented Nov 20, 2021

Sorry I've had too many other things that are higher priority since we are using the other published repo at the moment and it's working. It would be nicer to migrate to fastapi-oidc and have a common codebase instead

The merge is a bit messy since master is another 5 commits ahead.

I think maybe taking a look at one small thing at a time might be the most viable.

idtoken_model was removed as an argument as it is enforced by
pydantic with type hinting in the depends statement

BREAKING CHANGE
base_authorization_server_uri is never used on its own and
openid_connect_url is already used by fastapi and says more
about what is going on

BREAKING CHANGE
chose between schemes, optional auth, reintroduce
idtoken_model, define scopes, and verify scope

BREAKING CHANGE
@samedii
Copy link
Contributor Author

samedii commented Dec 4, 2021

Only have a few commits left to cherry pick from. Will finish it tonight.

@francbartoli
Copy link

Hi @HarryMWinters and @samedii, I'm using fastapi-third-party-auth but I'm pretty much happy to switch to fastapi-oidconce this will be merged. So thanks a lot guys for these great packages! I'm just wondering if this will happen soon.

Also, one additional question: is the PKCE mode supported in the authorization code flow? Is it something of interest to support? May I help somehow?

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

Successfully merging this pull request may close these issues.

None yet

3 participants