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

Feature/refactor auth flow #60

Merged
merged 33 commits into from
Nov 5, 2023
Merged

Feature/refactor auth flow #60

merged 33 commits into from
Nov 5, 2023

Conversation

fisher60
Copy link
Member

Completely redesign the auth flow of Abandon Auth to use AA UI and redirects to complete the authentication process.

This PR is a WIP and I am creating for visibility as there will be some very important changes that completely overhaul the auth flow.

…ling

This separation will be important since the developer login will use the login flow of the new login page. The alert banners are to help with debugging, though we will want some type error alerting for users, we should probably do this a bit nicer.
…h endpoint for creating callback_uri and adding to dev app

just saving my progress to push to remote, this version is not working yet.
This allows us to use the the prisma client directly within our routers, this is a needed change to support batching queries
… a user's developer app

I have added a method to replace the existing list of callback URIs with a new one. This may not have been the best way to do this and could cause performance issues or be a really nice way to DoS our database, we should review this. I have also added a way for users to view specific developer applications, this will allow viewing of callback URIs.
@fisher60 fisher60 self-assigned this Oct 29, 2023
Placeholder so I can push and pull from remote
…eveloper login to use new auth flow, add env var for abandon auth internal application, remove unused environment variables

I have refactored the login auth flow to accept a developer application ID and callback URI that are used in combination to redirect the user to the verified callback URI after a successful abandon auth login. The internal developer dashboard/index page utilizes this new auth flow and can act as an example.
@fisher60 fisher60 requested a review from GDWR October 31, 2023 03:07
@fisher60 fisher60 marked this pull request as draft October 31, 2023 03:07
I have gone through and added some additional checks that should have been included and that Pyright caught. This includes some better error handling. I also added a copied error response for the 403 on the /ui/login endpoint. This must be refactored so that the error is raised within the same check for dev_app existing and the callback URIs not being empty as it could be abused to determine valid application IDs, which may be undesirable--better safe than sorry.
This is to help standardize JWT claims across the project and allow for better documentation for what to expect on a token claim and for the return type of the JWT dependency.
… refactor endpoints for new aud claim

The JWT should have scope and aud claims as per the existing issue for the auth rework. These will provide additional security and flexibility when using tokens created by abandonauth including the ability to distinguish abandon auth login tokens (for managing developer applications) from external identify tokens.
This value always needs to be set during normal use. We may want to handle this better in the future to allow first-time application startup.
This will make these unusable for now, but they will need to be refactored fully once the new auth flow is finalized.
… to allow space separated string

We need to distinguish required scopes from a JWT to better protect abandon auth endpoints. This is to prevent an applicatio from hijacking a user's abandon auth account and getting permissions to modify a user account/developer accounts belonging to a user.
This endpoint should be able to safely exchange an identify token. Scope is handled by the JWT generator function and will add additional scopes based on whether or not the token was generated for the abandon auth UI/developer login.
We were allowing user inputs to inject any callback URI for an application. This is bad. I have changed the callback endpoint to validate the application ID and callback URI before using it in a redirect response. This will protect against unexpected hijacking of the auth flow.
…refactor abandonauth dev login to use new flow.
…app router for new dependency and reorder conflicting endpoints, refactor index.py for new auth

This new auth dependency is not completely necessary as it just subclasses from JWTBearer, but it acts as a convenience for configuring JWTBearer to be used with developer applications. This change requires that authenticating users are accompanied by the developer application that the authentication is intended for.
@fisher60 fisher60 marked this pull request as ready for review November 4, 2023 02:34
@fisher60 fisher60 changed the title WIP: Feature/refactor auth flow Feature/refactor auth flow Nov 4, 2023
Copy link
Contributor

@GDWR GDWR left a comment

Choose a reason for hiding this comment

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

Added some comments, but happy to merge and have future PR fixes

.env.sample Outdated Show resolved Hide resolved
prisma/schema.prisma Show resolved Hide resolved
abandonauth/routers/ui.py Outdated Show resolved Hide resolved
abandonauth/routers/index.py Show resolved Hide resolved

def _generate_jwt(user_id: str, long_lived: bool = False) -> str:

def _generate_jwt(user_id: str, application_id_aud: str, long_lived: bool = False) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

is application_id_aud different to application_id?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, these values are identical. I felt it was a bit more clear to specify what the application ID is used for in this case though.

abandonauth/dependencies/auth/jwt.py Show resolved Hide resolved
abandonauth/models/developer_application.py Outdated Show resolved Hide resolved
abandonauth/routers/developer_application.py Outdated Show resolved Hide resolved
This variable having a default value was confusing since it implied the user was meant to type out the discord redirect rather than generate it.
This DTO had the incorrect typing of `list[str] | None` despite the callback_uris always returning either a list of strings or an empty list.
I can't imagine who added this, I vote it was Harris.
@fisher60 fisher60 requested a review from GDWR November 4, 2023 21:46
@fisher60
Copy link
Member Author

fisher60 commented Nov 4, 2023

closes #58

@fisher60 fisher60 merged commit 29c260d into main Nov 5, 2023
2 checks passed
@fisher60 fisher60 deleted the feature/refactor-auth-flow branch November 5, 2023 02:22
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.

2 participants