-
Notifications
You must be signed in to change notification settings - Fork 74
Add OAuth2 login #512
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
base: main
Are you sure you want to change the base?
Add OAuth2 login #512
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| -- Login with external identity and register/migrate user if not present/externally managed | ||
| CREATE FUNCTION ctfnote_private.login_with_extern("name" text, "role" ctfnote.role) | ||
| RETURNS ctfnote.jwt | ||
| AS $$ | ||
| DECLARE | ||
| log_user ctfnote_private.user; | ||
| BEGIN | ||
| INSERT INTO ctfnote_private.user ("login", "password", "role") | ||
| VALUES (login_with_extern.name, 'external', login_with_extern.role) | ||
| ON CONFLICT ("login") DO UPDATE | ||
| SET password = 'external', role = login_with_extern.role | ||
| RETURNING | ||
| * INTO log_user; | ||
| INSERT INTO ctfnote.profile ("id", "username") | ||
| VALUES (log_user.id, login_with_extern.name) | ||
| ON CONFLICT (id) DO UPDATE | ||
| SET username = login_with_extern.name; | ||
| RETURN (ctfnote_private.new_token (log_user.id))::ctfnote.jwt; | ||
| END; | ||
| $$ | ||
| LANGUAGE plpgsql | ||
| STRICT | ||
| SECURITY DEFINER; | ||
|
|
||
| GRANT EXECUTE ON FUNCTION ctfnote_private.login_with_extern TO user_anonymous; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm maybe because it is in the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is my first time working with graphql. As a result, I can't give a definitive answer. I created the graphql parts by immitating similar code in ctfnote.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I make the function public, the following payload returns a JWT: [{"operationName":"loginWithExtern","variables":{"name":"test","role":"USER_ADMIN"},"query":"mutation loginWithExtern($name: String!, $role: Role!) {\n loginWithExtern(input: {name: $name, role: $role}) {\n jwt\n __typename\n }\n}"}]But that payload does not work if the function is private. But maybe my graphql is just to primitive to come up with a working version.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After a bit more searching, I found that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to correct myself: That function still exists. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ALTER TABLE ctfnote.settings | ||
| ADD COLUMN "oauth2_enabled" boolean NOT NULL DEFAULT FALSE; | ||
|
|
||
| GRANT SELECT ("oauth2_enabled") ON ctfnote.settings TO user_anonymous; | ||
| GRANT UPDATE ("oauth2_enabled") ON ctfnote.settings TO user_postgraphile; |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you login with an external identity provider, you will note be able to also do password login? Why can't it be both? So that you set a password after doing a password reset in CTFNote and then you choose to use OAuth login or through your password and you enter the same account.
For example, we can initially set the password to null to prevent any authentication through password and
ON CONFLICThere we just do nothing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is definitively an option (after dropping the
NOT NULLconstraint).But in that case we would end up with the opposite situation: I have a local account and want to migrate it to external only. With that option, the best I can do is to choose a long, random password and immediately forget it. Since that is less impacting, I probably will change it that way in the upcoming days.