-
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
base: main
Are you sure you want to change the base?
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,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, | ||||||
|
Comment on lines
+20
to
+26
|
||||||
| 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 | ||||||
|
Comment on lines
+3
to
+30
|
||||||
| ); | ||||||
|
|
||||||
| 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); | ||||||
|
||||||
| CREATE INDEX IF NOT EXISTS idx_oauth_tokens_lookup ON oauth_tokens(token, token_type, is_revoked, expires_at); |
Copilot
AI
Mar 4, 2026
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.
oauth_redirect_uris does not prevent duplicate redirect URIs for the same client. Since redirect URI matching is security-sensitive, consider adding a UNIQUE constraint (or unique index) on (client_id, redirect_uri) and indexing that pair for lookup.
| CREATE INDEX IF NOT EXISTS idx_oauth_redirect_uris_client_id ON oauth_redirect_uris(client_id); | |
| CREATE UNIQUE INDEX IF NOT EXISTS idx_oauth_redirect_uris_client_id_redirect_uri ON oauth_redirect_uris(client_id, redirect_uri); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7167,6 +7167,73 @@ CREATE TABLE public.notification_seen ( | |||||||||||||||
| ); | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| -- | ||||||||||||||||
| -- Name: oauth_authorization_codes; Type: TABLE; Schema: public; Owner: - | ||||||||||||||||
| -- | ||||||||||||||||
|
|
||||||||||||||||
| CREATE TABLE public.oauth_authorization_codes ( | ||||||||||||||||
| code character varying(255) NOT NULL, | ||||||||||||||||
| client_id character varying(255) NOT NULL, | ||||||||||||||||
| user_id integer NOT NULL, | ||||||||||||||||
| redirect_uri text NOT NULL, | ||||||||||||||||
| code_challenge character varying(255) NOT NULL, | ||||||||||||||||
| code_challenge_method character varying(10) DEFAULT 'S256'::character varying NOT NULL, | ||||||||||||||||
| scope character varying(50) NOT NULL, | ||||||||||||||||
| expires_at timestamp with time zone DEFAULT (now() + '00:10:00'::interval) NOT NULL, | ||||||||||||||||
| used boolean DEFAULT false NOT NULL | ||||||||||||||||
| ); | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| -- | ||||||||||||||||
| -- Name: oauth_redirect_uris; Type: TABLE; Schema: public; Owner: - | ||||||||||||||||
| -- | ||||||||||||||||
|
|
||||||||||||||||
| CREATE TABLE public.oauth_redirect_uris ( | ||||||||||||||||
| id integer NOT NULL, | ||||||||||||||||
| client_id character varying(255) NOT NULL, | ||||||||||||||||
| redirect_uri text NOT NULL, | ||||||||||||||||
| created_at timestamp with time zone DEFAULT now() NOT NULL | ||||||||||||||||
|
||||||||||||||||
| created_at timestamp with time zone DEFAULT now() NOT NULL | |
| created_at timestamp with time zone DEFAULT now() NOT NULL, | |
| UNIQUE (client_id, redirect_uri) |
rickyrombo marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Mar 4, 2026
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.
idx_oauth_tokens_lookup is redundant with the PRIMARY KEY index on oauth_tokens.token because the composite index starts with token. Consider removing it (or replacing with an index that supports non-PK queries, e.g., by token_type/is_revoked/expires_at).
| -- Name: idx_oauth_tokens_lookup; Type: INDEX; Schema: public; Owner: - | |
| -- | |
| CREATE INDEX idx_oauth_tokens_lookup ON public.oauth_tokens USING btree (token, token_type, is_revoked, expires_at); | |
| -- |
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.
code_challenge_methodis free-form VARCHAR; PKCE only allows specific values (typicallyS256orplain). Add a CHECK constraint (or enum type) to restrict this column to supported methods to prevent invalid rows that the auth flow can’t verify.