feat: add OAuth2 applications (#11197)

* Add database tables for OAuth2 applications

These are applications that will be able to use OAuth2 to get an API key
from Coder.

* Add endpoints for managing OAuth2 applications

These let you add, update, and remove OAuth2 applications.

* Add frontend for managing OAuth2 applications
This commit is contained in:
Asher
2023-12-21 12:38:42 -09:00
committed by GitHub
parent e044d3b752
commit 5cfa34b31e
47 changed files with 4281 additions and 1 deletions

View File

@ -0,0 +1,2 @@
DROP TABLE oauth2_provider_app_secrets;
DROP TABLE oauth2_provider_apps;

View File

@ -0,0 +1,25 @@
CREATE TABLE oauth2_provider_apps (
id uuid NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
name varchar(64) NOT NULL,
icon varchar(256) NOT NULL,
callback_url text NOT NULL,
PRIMARY KEY (id),
UNIQUE(name)
);
COMMENT ON TABLE oauth2_provider_apps IS 'A table used to configure apps that can use Coder as an OAuth2 provider, the reverse of what we are calling external authentication.';
CREATE TABLE oauth2_provider_app_secrets (
id uuid NOT NULL,
created_at timestamp with time zone NOT NULL,
last_used_at timestamp with time zone NULL,
hashed_secret bytea NOT NULL,
display_secret text NOT NULL,
app_id uuid NOT NULL REFERENCES oauth2_provider_apps (id) ON DELETE CASCADE,
PRIMARY KEY (id),
UNIQUE(app_id, hashed_secret)
);
COMMENT ON COLUMN oauth2_provider_app_secrets.display_secret IS 'The tail end of the original secret so secrets can be differentiated.';

View File

@ -0,0 +1,21 @@
INSERT INTO oauth2_provider_apps
(id, created_at, updated_at, name, icon, callback_url)
VALUES (
'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
'2023-06-15 10:23:54+00',
'2023-06-15 10:23:54+00',
'oauth2-app',
'/some/icon.svg',
'http://coder.com/oauth2/callback'
);
INSERT INTO oauth2_provider_app_secrets
(id, created_at, last_used_at, hashed_secret, display_secret, app_id)
VALUES (
'b0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
'2023-06-15 10:25:33+00',
'2023-12-15 11:40:20+00',
CAST('abcdefg' AS bytea),
'fg',
'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'
);