Skip to content

Commit

Permalink
Merge pull request #424 from sebadob/remove-obsoltete-refresh_token-v…
Browse files Browse the repository at this point in the history
…alue

Remove obsolete refresh token value
  • Loading branch information
sebadob committed May 9, 2024
2 parents 88f0241 + 33da02c commit 2ece6ed
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 55 deletions.
5 changes: 5 additions & 0 deletions dev_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## CURRENT WORK

## TODO before v0.23.0

- add `devices` + `refresh_tokens_devices` tables to `db_migrate()`
- make cookie setting configurable -> path(/auth) vs __Host-*

## Stage 1 - essentials

[x] finished
Expand Down
12 changes: 1 addition & 11 deletions frontend/src/components/admin/clients/ClientConfig.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
</div>
<div class="desc">
<p>
The allowed origins and the redirect URIs may contain a <code>*</code> wildcard only at the end.
The redirect URIs may contain a <code>*</code> wildcard only at the end.
</p>
</div>
Expand Down Expand Up @@ -470,16 +470,6 @@
</div>
</div>
<!-- Refresh Tokens -->
<div class="unit">
<div class="label font-label">
REFRESH TOKENS
</div>
<div class="value">
<Switch bind:selected={client.refresh_token}/>
</div>
</div>
<!-- PKCE Description -->
<div class="separator">
</div>
Expand Down
5 changes: 5 additions & 0 deletions migrations/postgres/25_remove_client_refresh_token.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- modify the clients table and remove obsolete `refresh_token` column
-- the new logic will just take a look at the flows_enabled value

alter table clients
drop column refresh_token;
219 changes: 219 additions & 0 deletions migrations/sqlite/25_remove_client_refresh_token.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
-- modify the clients table and remove obsolete `refresh_token` column
-- the new logic will just take a look at the flows_enabled value

alter table clients
rename to clients_old;

create table clients
(
id varchar not null
constraint clients_pk
primary key,
name varchar,
enabled bool not null,
confidential bool not null,
secret blob,
secret_kid varchar,
redirect_uris varchar not null,
post_logout_redirect_uris varchar,
allowed_origins varchar,
flows_enabled varchar not null,
access_token_alg varchar not null,
id_token_alg varchar not null,
auth_code_lifetime integer not null,
access_token_lifetime integer not null,
scopes varchar not null,
default_scopes varchar not null,
challenge varchar,
force_mfa bool not null,
client_uri varchar,
contacts varchar
);

insert into clients(id,
name,
enabled,
confidential,
secret,
secret_kid,
redirect_uris,
post_logout_redirect_uris,
allowed_origins,
flows_enabled,
access_token_alg,
id_token_alg,
auth_code_lifetime,
access_token_lifetime,
scopes,
default_scopes,
challenge,
force_mfa)
select id,
name,
enabled,
confidential,
secret,
secret_kid,
redirect_uris,
post_logout_redirect_uris,
allowed_origins,
flows_enabled,
access_token_alg,
id_token_alg,
auth_code_lifetime,
access_token_lifetime,
scopes,
default_scopes,
challenge,
false as force_mfa
from clients_old;

-- recreate all tables with foreign keys to clients

-- clients_dyn

alter table clients_dyn
rename to clients_dyn_old;

drop index clients_dyn_last_used_index;

create table clients_dyn
(
id text not null
constraint clients_dyn_pk
primary key
constraint clients_dyn_clients_id_fk
references clients
on update cascade on delete cascade,
created integer not null,
last_used integer,
registration_token blob not null,
token_endpoint_auth_method text not null
);

create index clients_dyn_last_used_index
on clients_dyn (last_used);

insert into clients_dyn(id, created, last_used, registration_token, token_endpoint_auth_method)
select id, created, last_used, registration_token, token_endpoint_auth_method
from clients_dyn_old;

-- colors
alter table colors
rename to colors_old;

create table colors
(
client_id varchar not null
constraint colors_pk
primary key
constraint colors_clients_id_fk
references clients
on update cascade
on delete cascade,
data blob not null
);

insert into colors(client_id, data)
select client_id, data
from colors_old;

-- client_logos
alter table client_logos
rename to client_logos_old;

create table client_logos
(
client_id varchar not null
constraint client_logos_client_id_fk
references clients
on update cascade on delete cascade,
res varchar not null,
content_type varchar not null,
data blob not null,
constraint client_logos_pk
primary key (client_id, res)
);
insert into client_logos(client_id, res, content_Type, data)
select client_id, res, content_Type, data
from client_logos_old;

-- devices
alter table devices
rename to devices_old;

drop index devices_access_exp_refresh_exp_index;

create table devices
(
id varchar not null
constraint devices_pk
primary key,
client_id varchar not null
constraint devices_clients_id_fk
references clients
on update cascade on delete cascade,
user_id varchar
constraint devices_users_id_fk
references users
on update cascade on delete cascade,
created bigint not null,
access_exp bigint not null,
refresh_exp bigint,
peer_ip varchar not null,
name varchar not null
);

create index devices_access_exp_refresh_exp_index
on devices (access_exp, refresh_exp);

insert into devices(id, client_id, user_id, created, access_exp, refresh_exp, peer_ip, name)
select id,
client_id,
user_id,
created,
access_exp,
refresh_exp,
peer_ip,
name
from devices_old;

-- refresh_tokens_devices
alter table refresh_tokens_devices
rename to refresh_tokens_devices_old;

drop index refresh_tokens_devices_exp_index;

create table refresh_tokens_devices
(
id varchar not null
constraint refresh_tokens_devices_pk
primary key,
device_id varchar not null
constraint refresh_tokens_devices_devices_id_fk
references devices
on update cascade on delete cascade,
user_id varchar not null
constraint refresh_tokens_users_user_id_fk
references users
on update cascade on delete cascade,
nbf bigint not null,
exp bigint not null,
scope varchar
);

create index refresh_tokens_devices_exp_index
on refresh_tokens_devices (exp);

insert into refresh_tokens_devices(id, device_id, user_id, nbf, exp, scope)
select id, device_id, user_id, nbf, exp, scope
from refresh_tokens_devices_old;

-- finally, drop all the old tables

drop table clients_dyn_old;
drop table colors_old;
drop table client_logos_old;
drop table clients_old;
drop table devices_old;
drop table refresh_tokens_devices_old;
Loading

0 comments on commit 2ece6ed

Please sign in to comment.