-
-
Notifications
You must be signed in to change notification settings - Fork 241
refactor: rework oidc session storage #913
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
Merged
+786
−2,339
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ed94490
refactor: use new cache store in auth service
steveiliop56 3e5757c
fix: fix race conditions
steveiliop56 ac9689d
tests: add cache store tests
steveiliop56 fe84638
fix: fix bugs in cache order
steveiliop56 82d21c3
Merge branch 'refactor/service-cache' into refactor/oidc-codes
steveiliop56 695feca
refactor: rework oidc session storage
steveiliop56 faa3156
Merge branch 'main' into refactor/oidc-store
steveiliop56 83ed9ec
feat: add db cleanup routine back
steveiliop56 4fe5de2
chore: fix memory store
steveiliop56 a723004
tests: fix oidc service tests
steveiliop56 1c4ca8f
chore: differentiate oauth userinfo from oidc userinfo
steveiliop56 b5770ef
fix: add memory back in the db bootstrap
steveiliop56 5caee88
fix: ensure no oidc code reuse
steveiliop56 b3c152f
chore: rabbit comments
steveiliop56 b636e6f
fix: use withlock for get oidc code entry
steveiliop56 6ff7e11
fix: fix typo in get code entry
steveiliop56 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
internal/assets/migrations/postgres/000002_oidc_rework.down.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| DROP TABLE IF EXISTS "oidc_sessions"; | ||
|
|
||
| CREATE TABLE "oidc_codes" ( | ||
| "sub" TEXT NOT NULL UNIQUE, | ||
| "code_hash" TEXT NOT NULL PRIMARY KEY, | ||
| "scope" TEXT NOT NULL, | ||
| "redirect_uri" TEXT NOT NULL, | ||
| "client_id" TEXT NOT NULL, | ||
| "expires_at" BIGINT NOT NULL, | ||
| "nonce" TEXT NOT NULL DEFAULT '', | ||
| "code_challenge" TEXT NOT NULL DEFAULT '' | ||
| ); | ||
|
|
||
| CREATE TABLE "oidc_tokens" ( | ||
| "sub" TEXT NOT NULL UNIQUE, | ||
| "access_token_hash" TEXT NOT NULL PRIMARY KEY, | ||
| "refresh_token_hash" TEXT NOT NULL, | ||
| "code_hash" TEXT NOT NULL, | ||
| "scope" TEXT NOT NULL, | ||
| "client_id" TEXT NOT NULL, | ||
| "token_expires_at" BIGINT NOT NULL, | ||
| "refresh_token_expires_at" BIGINT NOT NULL, | ||
| "nonce" TEXT NOT NULL DEFAULT '' | ||
| ); | ||
|
|
||
| CREATE TABLE "oidc_userinfo" ( | ||
| "sub" TEXT NOT NULL PRIMARY KEY, | ||
| "name" TEXT NOT NULL, | ||
| "preferred_username" TEXT NOT NULL, | ||
| "email" TEXT NOT NULL, | ||
| "groups" TEXT NOT NULL, | ||
| "updated_at" BIGINT NOT NULL, | ||
| "given_name" TEXT NOT NULL, | ||
| "family_name" TEXT NOT NULL, | ||
| "middle_name" TEXT NOT NULL, | ||
| "nickname" TEXT NOT NULL, | ||
| "profile" TEXT NOT NULL, | ||
| "picture" TEXT NOT NULL, | ||
| "website" TEXT NOT NULL, | ||
| "gender" TEXT NOT NULL, | ||
| "birthdate" TEXT NOT NULL, | ||
| "zoneinfo" TEXT NOT NULL, | ||
| "locale" TEXT NOT NULL, | ||
| "phone_number" TEXT NOT NULL, | ||
| "address" TEXT NOT NULL | ||
| ); |
28 changes: 28 additions & 0 deletions
28
internal/assets/migrations/postgres/000002_oidc_rework.up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| This migration will nuke the entire setup of OIDC sessions and merge everything | ||
| into one table. | ||
| */ | ||
|
|
||
| /* | ||
| Drop all the old tables. Yes, we will log out all OIDC users, but not really a big deal | ||
| */ | ||
|
|
||
| DROP TABLE IF EXISTS "oidc_tokens"; | ||
| DROP TABLE IF EXISTS "oidc_userinfo"; | ||
| DROP TABLE IF EXISTS "oidc_codes"; | ||
|
|
||
| /* | ||
| Create a new simple OIDC sessions table that will hold tokens + userinfo. | ||
| */ | ||
|
|
||
| CREATE TABLE IF NOT EXISTS "oidc_sessions" ( | ||
| "sub" TEXT NOT NULL UNIQUE PRIMARY KEY, | ||
| "access_token_hash" TEXT NOT NULL UNIQUE, | ||
| "refresh_token_hash" TEXT NOT NULL UNIQUE, | ||
| "scope" TEXT NOT NULL, | ||
| "client_id" TEXT NOT NULL, | ||
| "token_expires_at" BIGINT NOT NULL, | ||
| "refresh_token_expires_at" BIGINT NOT NULL, | ||
| "nonce" TEXT NOT NULL DEFAULT '', | ||
| "userinfo_json" TEXT NOT NULL | ||
| ); |
46 changes: 46 additions & 0 deletions
46
internal/assets/migrations/sqlite/000010_oidc_rework.down.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| DROP TABLE IF EXISTS "oidc_sessions"; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS "oidc_codes" ( | ||
| "sub" TEXT NOT NULL UNIQUE, | ||
| "code_hash" TEXT NOT NULL PRIMARY KEY UNIQUE, | ||
| "scope" TEXT NOT NULL, | ||
| "redirect_uri" TEXT NOT NULL, | ||
| "client_id" TEXT NOT NULL, | ||
| "expires_at" INTEGER NOT NULL, | ||
| "nonce" TEXT DEFAULT "", | ||
| "code_challenge" TEXT DEFAULT "" | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS "oidc_tokens" ( | ||
| "sub" TEXT NOT NULL UNIQUE, | ||
| "access_token_hash" TEXT NOT NULL PRIMARY KEY UNIQUE, | ||
| "refresh_token_hash" TEXT NOT NULL, | ||
| "code_hash" TEXT NOT NULL, | ||
| "scope" TEXT NOT NULL, | ||
| "client_id" TEXT NOT NULL, | ||
| "token_expires_at" INTEGER NOT NULL, | ||
| "refresh_token_expires_at" INTEGER NOT NULL, | ||
| "nonce" TEXT DEFAULT "" | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS "oidc_userinfo" ( | ||
| "sub" TEXT NOT NULL UNIQUE PRIMARY KEY, | ||
| "name" TEXT NOT NULL, | ||
| "preferred_username" TEXT NOT NULL, | ||
| "email" TEXT NOT NULL, | ||
| "groups" TEXT NOT NULL, | ||
| "updated_at" INTEGER NOT NULL, | ||
| "given_name" TEXT NOT NULL, | ||
| "family_name" TEXT NOT NULL, | ||
| "middle_name" TEXT NOT NULL, | ||
| "nickname" TEXT NOT NULL, | ||
| "profile" TEXT NOT NULL, | ||
| "picture" TEXT NOT NULL, | ||
| "website" TEXT NOT NULL, | ||
| "gender" TEXT NOT NULL, | ||
| "birthdate" TEXT NOT NULL, | ||
| "zoneinfo" TEXT NOT NULL, | ||
| "locale" TEXT NOT NULL, | ||
| "phone_number" TEXT NOT NULL, | ||
| "address" TEXT NOT NULL | ||
| ); |
28 changes: 28 additions & 0 deletions
28
internal/assets/migrations/sqlite/000010_oidc_rework.up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| This migration will nuke the entire setup of OIDC sessions and merge everything | ||
| into one table. | ||
| */ | ||
|
|
||
| /* | ||
| Drop all the old tables. Yes, we will log out all OIDC users, but not really a big deal | ||
| */ | ||
|
|
||
| DROP TABLE IF EXISTS "oidc_tokens"; | ||
| DROP TABLE IF EXISTS "oidc_userinfo"; | ||
| DROP TABLE IF EXISTS "oidc_codes"; | ||
|
|
||
| /* | ||
| Create a new simple OIDC sessions table that will hold tokens + userinfo. | ||
| */ | ||
|
|
||
| CREATE TABLE IF NOT EXISTS "oidc_sessions" ( | ||
| "sub" TEXT NOT NULL UNIQUE PRIMARY KEY, | ||
| "access_token_hash" TEXT NOT NULL UNIQUE, | ||
| "refresh_token_hash" TEXT NOT NULL UNIQUE, | ||
| "scope" TEXT NOT NULL, | ||
| "client_id" TEXT NOT NULL, | ||
| "token_expires_at" INTEGER NOT NULL, | ||
| "refresh_token_expires_at" INTEGER NOT NULL, | ||
| "nonce" TEXT DEFAULT "", | ||
| "userinfo_json" TEXT NOT NULL | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.