-
Notifications
You must be signed in to change notification settings - Fork 1
Add tables for PKCE OAuth2.0 #685
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
+205
−1
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| BEGIN; | ||
|
|
||
| -- oauth_authorization_codes: short-lived (10 min), one-time-use authorization codes for PKCE flow | ||
| CREATE TABLE IF NOT EXISTS oauth_authorization_codes ( | ||
| code VARCHAR(255) NOT NULL PRIMARY KEY, | ||
| client_id VARCHAR(255) NOT NULL, | ||
| user_id INTEGER NOT NULL, | ||
| redirect_uri TEXT NOT NULL, | ||
| code_challenge VARCHAR(255) NOT NULL, | ||
| code_challenge_method VARCHAR(10) NOT NULL DEFAULT 'S256', | ||
| scope VARCHAR(50) NOT NULL, | ||
| expires_at TIMESTAMPTZ NOT NULL DEFAULT (NOW() + INTERVAL '10 minutes'), | ||
| used BOOLEAN NOT NULL DEFAULT false | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_oauth_authorization_codes_client_id ON oauth_authorization_codes(client_id); | ||
| CREATE INDEX IF NOT EXISTS idx_oauth_authorization_codes_expires_used ON oauth_authorization_codes(expires_at, used); | ||
|
|
||
| -- oauth_tokens: opaque access and refresh tokens for PKCE flow | ||
| CREATE TABLE IF NOT EXISTS oauth_tokens ( | ||
| token VARCHAR(255) NOT NULL PRIMARY KEY, | ||
| token_type VARCHAR(10) NOT NULL, | ||
| client_id VARCHAR(255) NOT NULL, | ||
| user_id INTEGER NOT NULL, | ||
| scope VARCHAR(50) NOT NULL, | ||
| expires_at TIMESTAMPTZ NOT NULL, | ||
rickyrombo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| is_revoked BOOLEAN NOT NULL DEFAULT false, | ||
| created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
| refresh_token_id VARCHAR(255), | ||
| family_id VARCHAR(255) NOT NULL | ||
rickyrombo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_oauth_tokens_client_id ON oauth_tokens(client_id); | ||
| CREATE INDEX IF NOT EXISTS idx_oauth_tokens_user_id ON oauth_tokens(user_id); | ||
| CREATE INDEX IF NOT EXISTS idx_oauth_tokens_family_id ON oauth_tokens(family_id); | ||
| CREATE INDEX IF NOT EXISTS idx_oauth_tokens_refresh_token_id ON oauth_tokens(refresh_token_id); | ||
| CREATE INDEX IF NOT EXISTS idx_oauth_tokens_lookup ON oauth_tokens(token, token_type, is_revoked, expires_at); | ||
rickyrombo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| -- oauth_redirect_uris: pre-registered redirect URIs per app | ||
| CREATE TABLE IF NOT EXISTS oauth_redirect_uris ( | ||
| id SERIAL PRIMARY KEY, | ||
| client_id VARCHAR(255) NOT NULL, | ||
| redirect_uri TEXT NOT NULL, | ||
| created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_oauth_redirect_uris_client_id ON oauth_redirect_uris(client_id); | ||
rickyrombo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| COMMIT; | ||
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
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.