Skip to content

Commit 29761f4

Browse files
aeneasrzepatrik
andauthored
fix: force autocommit for device auth code migration (#3991)
<!-- Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. This text will be included in the changelog. If applicable, include links to documentation or pieces of code. If your change includes breaking changes please add a code block documenting the breaking change: ``` BREAKING CHANGES: This patch changes the behavior of configuration item `foo` to do bar. To keep the existing behavior please do baz. ``` --> ## Related issue(s) <!-- If this pull request 1. is a fix for a known bug, link the issue where the bug was reported in the format of `#1234`; 2. is a fix for a previously unknown bug, explain the bug and how to reproduce it in this pull request; 3. implements a new feature, link the issue containing the design document in the format of `#1234`; 4. improves the documentation, no issue reference is required. Pull requests introducing new features, which do not have a design document linked are more likely to be rejected and take on average 2-8 weeks longer to get merged. You can discuss changes with maintainers either in the Github Discussions in this repository or join the [Ory Chat](https://www.ory.sh/chat). --> ## Checklist <!-- Put an `x` in the boxes that apply. You can also fill these out after creating the PR. Please be aware that pull requests must have all boxes ticked in order to be merged. If you're unsure about any of them, don't hesitate to ask. We're here to help! --> - [ ] I have read the [contributing guidelines](../blob/master/CONTRIBUTING.md). - [ ] I have referenced an issue containing the design document if my change introduces a new feature. - [ ] I am following the [contributing code guidelines](../blob/master/CONTRIBUTING.md#contributing-code). - [ ] I have read the [security policy](../security/policy). - [ ] I confirm that this pull request does not address a security vulnerability. If this pull request addresses a security vulnerability, I confirm that I got the approval (please contact [[email protected]](mailto:[email protected])) from the maintainers to push the changes. - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added or changed [the documentation](https://github.com/ory/docs). ## Further Comments <!-- If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... --> --------- Co-authored-by: zepatrik <[email protected]>
1 parent 5e2052e commit 29761f4

File tree

9 files changed

+374
-44
lines changed

9 files changed

+374
-44
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
{
2+
"AccessTokenStrategy": "",
3+
"AllowedCORSOrigins": [
4+
"http://cors/23_1",
5+
"http://cors/23_2"
6+
],
7+
"Audience": [
8+
"autdience-23_1",
9+
"autdience-23_2"
10+
],
11+
"BackChannelLogoutSessionRequired": true,
12+
"BackChannelLogoutURI": "http://back_logout/23",
13+
"ClientURI": "http://client/23",
14+
"Contacts": [
15+
"contact-23_1",
16+
"contact-23_2"
17+
],
18+
"CreatedAt": "0001-01-01T00:00:00Z",
19+
"FrontChannelLogoutSessionRequired": true,
20+
"FrontChannelLogoutURI": "http://front_logout/23",
21+
"GrantTypes": [
22+
"grant-23_1",
23+
"grant-23_2"
24+
],
25+
"ID": "client-23",
26+
"JSONWebKeys": {
27+
"JSONWebKeySet": null
28+
},
29+
"JSONWebKeysURI": "http://jwks/23",
30+
"Lifespans": {
31+
"AuthorizationCodeGrantAccessTokenLifespan": {
32+
"Duration": 0,
33+
"Valid": false
34+
},
35+
"AuthorizationCodeGrantIDTokenLifespan": {
36+
"Duration": 0,
37+
"Valid": false
38+
},
39+
"AuthorizationCodeGrantRefreshTokenLifespan": {
40+
"Duration": 0,
41+
"Valid": false
42+
},
43+
"ClientCredentialsGrantAccessTokenLifespan": {
44+
"Duration": 0,
45+
"Valid": false
46+
},
47+
"DeviceAuthorizationGrantAccessTokenLifespan": {
48+
"Duration": 3600,
49+
"Valid": true
50+
},
51+
"DeviceAuthorizationGrantIDTokenLifespan": {
52+
"Duration": 3600,
53+
"Valid": true
54+
},
55+
"DeviceAuthorizationGrantRefreshTokenLifespan": {
56+
"Duration": 3600,
57+
"Valid": true
58+
},
59+
"ImplicitGrantAccessTokenLifespan": {
60+
"Duration": 0,
61+
"Valid": false
62+
},
63+
"ImplicitGrantIDTokenLifespan": {
64+
"Duration": 0,
65+
"Valid": false
66+
},
67+
"JwtBearerGrantAccessTokenLifespan": {
68+
"Duration": 0,
69+
"Valid": false
70+
},
71+
"PasswordGrantAccessTokenLifespan": {
72+
"Duration": 0,
73+
"Valid": false
74+
},
75+
"PasswordGrantRefreshTokenLifespan": {
76+
"Duration": 0,
77+
"Valid": false
78+
},
79+
"RefreshTokenGrantAccessTokenLifespan": {
80+
"Duration": 0,
81+
"Valid": false
82+
},
83+
"RefreshTokenGrantIDTokenLifespan": {
84+
"Duration": 0,
85+
"Valid": false
86+
},
87+
"RefreshTokenGrantRefreshTokenLifespan": {
88+
"Duration": 0,
89+
"Valid": false
90+
}
91+
},
92+
"LogoURI": "http://logo/23",
93+
"Metadata": {
94+
"migration": "23"
95+
},
96+
"NID": "00000000-0000-0000-0000-000000000000",
97+
"Name": "Client 23",
98+
"Owner": "owner-23",
99+
"PK": {
100+
"String": "",
101+
"Valid": false
102+
},
103+
"PKDeprecated": 0,
104+
"PolicyURI": "http://policy/23",
105+
"PostLogoutRedirectURIs": [
106+
"http://post_redirect/23_1",
107+
"http://post_redirect/23_2"
108+
],
109+
"RedirectURIs": [
110+
"http://redirect/23_1",
111+
"http://redirect/23_2"
112+
],
113+
"RegistrationAccessToken": "",
114+
"RegistrationAccessTokenSignature": "",
115+
"RegistrationClientURI": "",
116+
"RequestObjectSigningAlgorithm": "r_alg-23",
117+
"RequestURIs": [
118+
"http://request/23_1",
119+
"http://request/23_2"
120+
],
121+
"ResponseTypes": [
122+
"response-23_1",
123+
"response-23_2"
124+
],
125+
"Scope": "scope-23",
126+
"Secret": "secret-23",
127+
"SecretExpiresAt": 0,
128+
"SectorIdentifierURI": "http://sector_id/23",
129+
"SkipConsent": true,
130+
"SkipLogoutConsent": {
131+
"Bool": true,
132+
"Valid": true
133+
},
134+
"SubjectType": "subject-23",
135+
"TermsOfServiceURI": "http://tos/23",
136+
"TokenEndpointAuthMethod": "token_auth-23",
137+
"TokenEndpointAuthSigningAlgorithm": "",
138+
"UpdatedAt": "0001-01-01T00:00:00Z",
139+
"UserinfoSignedResponseAlg": "u_alg-23"
140+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"ID": "device-code-signature-0001",
3+
"UserCodeID": "user-code-signature-0001",
4+
"NID": "00000000-0000-0000-0000-000000000000",
5+
"Request": "request-id-0001",
6+
"ConsentChallenge": {
7+
"String": "challenge-0018",
8+
"Valid": true
9+
},
10+
"RequestedAt": "2025-05-16T12:24:00Z",
11+
"Client": "client-21",
12+
"Scopes": "[\"scope-0001_1\",\"scope-0001_2\"]",
13+
"GrantedScope": "[\"granted_scope-0001_1\",\"granted_scope-0001_2\"]",
14+
"RequestedAudience": "[\"requested_audience-0001_1\",\"requested_audience-0001_2\"]",
15+
"GrantedAudience": "[\"granted_audience-0001_1\",\"granted_audience-0001_2\"]",
16+
"Form": "{\"form_data\": \"0001\"}",
17+
"Subject": "subject-0001",
18+
"DeviceCodeActive": true,
19+
"UserCodeState": 0,
20+
"Session": "eyJzZXNzaW9uX2RhdGEiOiAiMDAwMSJ9"
21+
}

persistence/sql/migratest/fixtures/hydra_oauth2_flow/challenge-0018.json

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
"requested_audience-0018_1",
1010
"requested_audience-0018_2"
1111
],
12-
"ls": false,
12+
"ls": true,
1313
"s": "subject-0018",
14-
"oc": {},
14+
"oc": {
15+
"display": "display-0018"
16+
},
1517
"r": "http://request/0018",
16-
"si": "auth_session-0018",
1718
"lv": "verifier-0018",
1819
"lc": "csrf-0018",
1920
"li": null,
@@ -23,7 +24,10 @@
2324
"lf": 15,
2425
"ll": true,
2526
"a": "acr-0018",
26-
"am": [],
27+
"am": [
28+
"amr-0018-1",
29+
"amr-0018-2"
30+
],
2731
"fs": "force_subject_id-0018",
2832
"ct": {
2933
"context": "0018"
@@ -38,13 +42,20 @@
3842
"valid": false
3943
},
4044
"la": null,
41-
"di": "challenge-0018",
42-
"dr": "request-0018",
43-
"dv": "verifier-0018",
44-
"dc": "csrf-0018",
45+
"di": "device-challenge-0018",
46+
"dr": "device-request-id-0018",
47+
"dv": "device-verifier-0018",
48+
"dc": "device-csrf-0018",
4549
"du": true,
46-
"dh": "0001-01-01T00:00:00Z",
47-
"de": null,
50+
"dh": "2025-05-16T12:24:00Z",
51+
"de": {
52+
"error": "",
53+
"error_description": "",
54+
"error_hint": "",
55+
"status_code": 0,
56+
"error_debug": "",
57+
"valid": false
58+
},
4859
"cc": "challenge-0018",
4960
"cs": true,
5061
"cv": "verifier-0018",

persistence/sql/migratest/migration_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func TestMigrations(t *testing.T) {
124124
t.Run("case=hydra_client", func(t *testing.T) {
125125
cs := []client.Client{}
126126
require.NoError(t, c.All(&cs))
127-
require.Len(t, cs, 19)
127+
require.Len(t, cs, 20)
128128
for _, c := range cs {
129129
require.False(t, c.CreatedAt.IsZero())
130130
require.False(t, c.UpdatedAt.IsZero())
@@ -155,7 +155,7 @@ func TestMigrations(t *testing.T) {
155155

156156
flows := []flow.Flow{}
157157
require.NoError(t, c.All(&flows))
158-
require.Len(t, flows, 17)
158+
require.Len(t, flows, 18)
159159

160160
t.Run("case=hydra_oauth2_flow", func(t *testing.T) {
161161
for _, f := range flows {
@@ -294,6 +294,18 @@ func TestMigrations(t *testing.T) {
294294
}
295295
})
296296

297+
t.Run("case=hydra_oauth2_device_auth_codes", func(t *testing.T) {
298+
rs := []sql.DeviceRequestSQL{}
299+
require.NoError(t, c.All(&rs))
300+
require.Len(t, rs, 1)
301+
302+
for _, r := range rs {
303+
testhelpersuuid.AssertUUID(t, r.NID)
304+
r.NID = uuid.Nil
305+
CompareWithFixture(t, r, "hydra_oauth2_device_auth_codes", r.ID)
306+
}
307+
})
308+
297309
t.Run("case=networks", func(t *testing.T) {
298310
ns := []networkx.Network{}
299311
require.NoError(t, c.RawQuery("SELECT * FROM networks").All(&ns))
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
INSERT INTO hydra_client (id,
2+
nid,
3+
client_name,
4+
client_secret,
5+
redirect_uris,
6+
grant_types,
7+
response_types,
8+
scope,
9+
owner,
10+
policy_uri,
11+
tos_uri,
12+
client_uri,
13+
logo_uri,
14+
contacts,
15+
client_secret_expires_at,
16+
sector_identifier_uri,
17+
jwks,
18+
jwks_uri,
19+
request_uris,
20+
token_endpoint_auth_method,
21+
request_object_signing_alg,
22+
userinfo_signed_response_alg,
23+
subject_type,
24+
allowed_cors_origins,
25+
pk_deprecated,
26+
audience,
27+
created_at,
28+
updated_at,
29+
frontchannel_logout_uri,
30+
frontchannel_logout_session_required,
31+
post_logout_redirect_uris,
32+
backchannel_logout_uri,
33+
backchannel_logout_session_required,
34+
metadata,
35+
token_endpoint_auth_signing_alg,
36+
pk,
37+
registration_access_token_signature,
38+
skip_consent,
39+
skip_logout_consent,
40+
device_authorization_grant_id_token_lifespan,
41+
device_authorization_grant_access_token_lifespan,
42+
device_authorization_grant_refresh_token_lifespan)
43+
VALUES ('client-23',
44+
(SELECT id FROM networks LIMIT 1), 'Client 23', 'secret-23', '["http://redirect/23_1","http://redirect/23_2"]', '["grant-23_1","grant-23_2"]', '["response-23_1","response-23_2"]', 'scope-23', 'owner-23', 'http://policy/23', 'http://tos/23', 'http://client/23', 'http://logo/23', '["contact-23_1","contact-23_2"]', 0, 'http://sector_id/23', '', 'http://jwks/23', '["http://request/23_1","http://request/23_2"]', 'token_auth-23', 'r_alg-23', 'u_alg-23', 'subject-23', '["http://cors/23_1","http://cors/23_2"]', 0, '["autdience-23_1","autdience-23_2"]', '2023-02-15 23:20:23.004598', '2023-02-15 23:20:23.004598', 'http://front_logout/23', true, '["http://post_redirect/23_1","http://post_redirect/23_2"]', 'http://back_logout/23', true, '{"migration": "23"}', '', '52f38352-7944-4ace-b55c-5aded28f4ba6', '', TRUE, TRUE, 3600, 3600, 3600);
45+
46+
47+
INSERT INTO hydra_oauth2_flow (login_challenge,
48+
nid,
49+
requested_scope,
50+
login_verifier,
51+
login_csrf,
52+
subject,
53+
request_url,
54+
login_skip,
55+
client_id,
56+
requested_at,
57+
oidc_context,
58+
login_session_id,
59+
requested_at_audience,
60+
login_initialized_at,
61+
state,
62+
login_remember,
63+
login_remember_for,
64+
login_error,
65+
acr,
66+
login_authenticated_at,
67+
login_was_used,
68+
forced_subject_identifier,
69+
context,
70+
amr,
71+
consent_challenge_id,
72+
consent_verifier,
73+
consent_skip,
74+
consent_csrf,
75+
granted_scope,
76+
consent_remember,
77+
consent_remember_for,
78+
consent_error,
79+
session_access_token,
80+
session_id_token,
81+
consent_was_used,
82+
granted_at_audience,
83+
consent_handled_at,
84+
login_extend_session_lifespan,
85+
device_challenge_id,
86+
device_code_request_id,
87+
device_verifier,
88+
device_csrf,
89+
device_was_used,
90+
device_handled_at,
91+
device_error)
92+
VALUES ('challenge-0018',
93+
(SELECT id FROM networks LIMIT 1), '["requested_scope-0018_1","requested_scope-0018_2"]', 'verifier-0018', 'csrf-0018', 'subject-0018', 'http://request/0018', true, 'client-21', '2025-05-16 12:24', '{"display": "display-0018"}', NULL, '["requested_audience-0018_1","requested_audience-0018_2"]', '2025-05-16 12:24', 128, true, 15, '{}', 'acr-0018', '2025-05-16 12:24', true, 'force_subject_id-0018', '{"context": "0018"}', '["amr-0018-1","amr-0018-2"]', 'challenge-0018', 'verifier-0018', true, 'csrf-0018', '["granted_scope-0018_1","granted_scope-0018_2"]', true, 15, '{}', '{"session_access_token-0018": "0018"}', '{"session_id_token-0018": "0018"}', true, '["granted_audience-0018_1","granted_audience-0018_2"]', '2025-05-16 12:24', true, 'device-challenge-0018', 'device-request-id-0018', 'device-verifier-0018', 'device-csrf-0018', true, '2025-05-16 12:24', '{}' );
94+
95+
INSERT INTO hydra_oauth2_device_auth_codes (device_code_signature, user_code_signature, request_id, requested_at,
96+
client_id, scope, granted_scope, form_data, session_data, subject,
97+
device_code_active, user_code_state, requested_audience, granted_audience,
98+
challenge_id, expires_at, nid)
99+
VALUES ('device-code-signature-0001', 'user-code-signature-0001', 'request-id-0001', '2025-05-16 12:24',
100+
'client-21', '["scope-0001_1","scope-0001_2"]', '["granted_scope-0001_1","granted_scope-0001_2"]',
101+
'{"form_data": "0001"}',
102+
'{"session_data": "0001"}', 'subject-0001', true, 0,
103+
'["requested_audience-0001_1","requested_audience-0001_2"]',
104+
'["granted_audience-0001_1","granted_audience-0001_2"]', 'challenge-0018', '2025-05-16 12:24',
105+
(SELECT id FROM networks LIMIT 1)
106+
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
DROP TABLE IF EXISTS hydra_oauth2_device_auth_codes;
2+
3+
ALTER TABLE hydra_oauth2_flow
4+
DROP COLUMN IF EXISTS device_challenge_id,
5+
DROP COLUMN IF EXISTS device_code_request_id,
6+
DROP COLUMN IF EXISTS device_verifier,
7+
DROP COLUMN IF EXISTS device_csrf,
8+
DROP COLUMN IF EXISTS device_was_used,
9+
DROP COLUMN IF EXISTS device_handled_at,
10+
DROP COLUMN IF EXISTS device_error;
11+
12+
ALTER TABLE hydra_client
13+
DROP COLUMN IF EXISTS device_authorization_grant_id_token_lifespan,
14+
DROP COLUMN IF EXISTS device_authorization_grant_access_token_lifespan,
15+
DROP COLUMN IF EXISTS device_authorization_grant_refresh_token_lifespan;

0 commit comments

Comments
 (0)