Repository navigation
refactor: rework auth and session layer #1235
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
Open
steveiliop56
wants to merge
24
commits into
main
Choose a base branch
from
refactor/sessions-csrf
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
80fef66
wip: initial schema
steveiliop56 2abcb18
wip: add new services for identity, sessions and oauth
steveiliop56 c8ebbbb
refactor: migrate oauth controller to new identity model
steveiliop56 a50c3c1
refactor: update context middleware
steveiliop56 e79431e
refactor: adapt user controller to new services
steveiliop56 6654fe4
wip: working prototype
steveiliop56 c16daa8
chore: remove csrf token from db
steveiliop56 afe1f0f
deps: bump go to 1.27.3
steveiliop56 d1c9f73
feat: make linking mode configurable
steveiliop56 d2e888e
tests: fix controller tests
steveiliop56 4c1f12e
tests: fix service tests
steveiliop56 527011d
tests: fix middleware tests
steveiliop56 7d715bf
tests: fix model tests
steveiliop56 2278504
tests: add tests for sessions and identity service
steveiliop56 fdff696
fix: build webui before code gen
steveiliop56 5745d11
fix: copy frontend before codegen checks in ci
steveiliop56 169f47a
chore: remove deprecated version file
steveiliop56 90b1c36
fix: batch no 1 of review comments
steveiliop56 f503198
refactor: use a factory to support stores with transactions
steveiliop56 2a7dd8d
chore: use different db for each test
steveiliop56 0f73071
fix: review comments
steveiliop56 5135c1d
tests: add tests for identity service
steveiliop56 d5c7652
fix: retry serilization on transaction
steveiliop56 3a1cd75
tests: use database id in file name
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
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
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
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
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
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
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
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
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 |
|---|---|---|
|
|
@@ -92,7 +92,7 @@ sql: | |
| sqlc generate | ||
|
|
||
| # Go gen | ||
| generate: | ||
| generate: webui | ||
| go generate ./... | ||
|
|
||
| # an alias for generate | ||
|
|
||
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
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
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| module github.com/tinyauthapp/tinyauth | ||
|
|
||
| go 1.26.4 | ||
| go 1.27.3 | ||
|
|
||
| require ( | ||
| charm.land/huh/v2 v2.0.3 | ||
|
|
||
4 changes: 4 additions & 0 deletions
4
sql/postgres/session_schemas.sql → ...rations/postgres/000004_identity.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
41 changes: 41 additions & 0 deletions
41
internal/assets/migrations/postgres/000004_identity.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,41 @@ | ||
| /* | ||
| Drop the old, legacy, terrible sessions table | ||
|
|
||
| Will log out all users, but that's fine. | ||
| */ | ||
|
|
||
| DROP TABLE IF EXISTS "sessions"; | ||
|
|
||
| /* | ||
| The new structure consists of the following: | ||
|
|
||
| Users: holds the user data like the username, password, etc. | ||
| Identities: links the user to the identity provider. | ||
| Sessions: holds the session data like the UUID, CSRF, expiration time, etc. | ||
| */ | ||
|
|
||
| CREATE TABLE IF NOT EXISTS "users" ( | ||
| "uuid" TEXT PRIMARY KEY, | ||
| "username" TEXT NOT NULL, | ||
| "email" TEXT NOT NULL, | ||
| "name" TEXT NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS "identities" ( | ||
| "uuid" TEXT PRIMARY KEY, | ||
| "user_uuid" TEXT NOT NULL, | ||
| "provider_type" TEXT NOT NULL, | ||
| "provider" TEXT NOT NULL, | ||
| "provider_user_id" TEXT NOT NULL, | ||
| "context_json" TEXT NOT NULL, | ||
| FOREIGN KEY("user_uuid") REFERENCES "users"("uuid") ON DELETE CASCADE | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS "sessions" ( | ||
| "uuid" TEXT PRIMARY KEY, | ||
| "identity_uuid" TEXT NOT NULL, | ||
| "expires_at" BIGINT NOT NULL, | ||
| "created_at" BIGINT NOT NULL, | ||
| "context_json" TEXT NOT NULL, | ||
| FOREIGN KEY("identity_uuid") REFERENCES "identities"("uuid") ON DELETE CASCADE | ||
| ); |
4 changes: 4 additions & 0 deletions
4
sql/sqlite/session_schemas.sql → ...igrations/sqlite/000012_identity.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
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,41 @@ | ||
| /* | ||
| Drop the old, legacy, terrible sessions table | ||
|
|
||
| Will log out all users, but that's fine. | ||
| */ | ||
|
|
||
| DROP TABLE IF EXISTS "sessions"; | ||
|
|
||
| /* | ||
| The new structure consists of the following: | ||
|
|
||
| Users: holds the user data like the username, password, etc. | ||
| Identities: links the user to the identity provider. | ||
| Sessions: holds the session data like the UUID, CSRF, expiration time, etc. | ||
| */ | ||
|
|
||
| CREATE TABLE IF NOT EXISTS "users" ( | ||
| "uuid" TEXT PRIMARY KEY, | ||
| "username" TEXT NOT NULL, | ||
| "email" TEXT NOT NULL, | ||
| "name" TEXT NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS "identities" ( | ||
| "uuid" TEXT PRIMARY KEY, | ||
| "user_uuid" TEXT NOT NULL, | ||
| "provider_type" TEXT NOT NULL, | ||
| "provider" TEXT NOT NULL, | ||
| "provider_user_id" TEXT NOT NULL, | ||
| "context_json" TEXT NOT NULL, | ||
| FOREIGN KEY("user_uuid") REFERENCES "users"("uuid") ON DELETE CASCADE | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS "sessions" ( | ||
| "uuid" TEXT PRIMARY KEY, | ||
| "identity_uuid" TEXT NOT NULL, | ||
| "expires_at" INTEGER NOT NULL, | ||
| "created_at" INTEGER NOT NULL, | ||
| "context_json" TEXT NOT NULL, | ||
| FOREIGN KEY("identity_uuid") REFERENCES "identities"("uuid") ON DELETE CASCADE | ||
| ); |
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.