Skip to content

Commit 09db63e

Browse files
authored
feat: make deep links work (#1071)
* ci: try automatically re-running tests * ci: try automatically re-running tests * ci: try automatically re-running tests * ci: try automatically re-running tests * ci: try automatically re-running tests * ci: try automatically re-running tests * ci: try automatically re-running tests * ci: try automatically re-running tests * ci: try automatically re-running tests * test: try and improve flaky tests * chore: changelog consistency with plugin * feat: make deep-links work
1 parent 8944bfd commit 09db63e

File tree

4 files changed

+56
-52
lines changed

4 files changed

+56
-52
lines changed

.circleci/config.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,30 @@ jobs:
1111
MONGO_INITDB_ROOT_USERNAME: root
1212
MONGO_INITDB_ROOT_PASSWORD: root
1313
resource_class: large
14+
parallelism: 4
1415
parameters:
1516
plugin:
1617
type: string
1718
steps:
1819
- checkout
20+
- run: mkdir ~/junit
1921
- run: echo $'\n[mysqld]\ncharacter_set_server=utf8mb4\nmax_connections=10000' >> /etc/mysql/mysql.cnf
2022
- run: apt-get update && apt-get -y -q install postgresql-9.5 postgresql-client-9.5 postgresql-contrib-9.5 sudo
2123
- run: echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.5/main/pg_hba.conf
2224
- run: echo "listen_addresses='*'" >> /etc/postgresql/9.5/main/postgresql.conf
2325
- run: sed -i 's/^#*\s*max_connections\s*=.*/max_connections = 10000/' /etc/postgresql/9.5/main/postgresql.conf
2426
- run: (cd .circleci/ && ./doTests.sh << parameters.plugin >>)
27+
- run:
28+
command: cp ~/supertokens-root/supertokens-core/build/test-results/test/*.xml ~/junit/
29+
when: always
30+
- when:
31+
condition:
32+
not:
33+
equal: [ << parameters.plugin >>, "sqlite" ]
34+
steps:
35+
- run: cp ~/supertokens-root/supertokens-<< parameters.plugin >>-plugin/build/test-results/test/*.xml ~/junit/
36+
- store_test_results:
37+
path: ~/junit
2538
- slack/status
2639

2740
mark-passed:
@@ -45,7 +58,7 @@ workflows:
4558
tags:
4659
only: /dev-v[0-9]+(\.[0-9]+)*/
4760
branches:
48-
ignore: /.*/
61+
only: /test-cicd\/.*/
4962
- test:
5063
plugin: mongodb
5164
name: test-mongodb
@@ -55,7 +68,7 @@ workflows:
5568
tags:
5669
only: /dev-v[0-9]+(\.[0-9]+)*/
5770
branches:
58-
ignore: /.*/
71+
only: /test-cicd\/.*/
5972
- test:
6073
plugin: postgresql
6174
name: test-postgresql
@@ -65,7 +78,7 @@ workflows:
6578
tags:
6679
only: /dev-v[0-9]+(\.[0-9]+)*/
6780
branches:
68-
ignore: /.*/
81+
only: /test-cicd\/.*/
6982
- test:
7083
plugin: mysql
7184
name: test-mysql
@@ -75,7 +88,7 @@ workflows:
7588
tags:
7689
only: /dev-v[0-9]+(\.[0-9]+)*/
7790
branches:
78-
ignore: /.*/
91+
only: /test-cicd\/.*/
7992
- mark-passed:
8093
context:
8194
- slack-notification

.circleci/doTests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ do
162162
fi
163163
cd ../
164164
echo $SUPERTOKENS_API_KEY > apiPassword
165+
165166
./startTestingEnv --cicd
166167

167168
if [[ $? -ne 0 ]]

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ CREATE TABLE IF NOT EXISTS oauth_clients (
107107
FOREIGN KEY(app_id) REFERENCES apps(app_id) ON DELETE CASCADE
108108
);
109109

110-
111110
CREATE TABLE IF NOT EXISTS oauth_sessions (
112111
gid VARCHAR(255),
113112
app_id VARCHAR(64) DEFAULT 'public',
@@ -121,8 +120,8 @@ CREATE TABLE IF NOT EXISTS oauth_sessions (
121120
FOREIGN KEY(app_id, client_id) REFERENCES oauth_clients(app_id, client_id) ON DELETE CASCADE
122121
);
123122

124-
CREATE INDEX IF NOT EXISTS oauth_session_exp_index ON oauth_sessions(exp DESC);
125-
CREATE INDEX IF NOT EXISTS oauth_session_external_refresh_token_index ON oauth_sessions(app_id, external_refresh_token DESC);
123+
CREATE INDEX oauth_session_exp_index ON oauth_sessions(exp DESC);
124+
CREATE INDEX oauth_session_external_refresh_token_index ON oauth_sessions(app_id, external_refresh_token DESC);
126125

127126
CREATE TABLE oauth_m2m_tokens (
128127
app_id VARCHAR(64) DEFAULT 'public',

src/main/java/io/supertokens/oauth/Transformations.java

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,23 @@ public static Map<String, String> transformRequestHeadersForHydra(Map<String, St
6868
}
6969

7070
private static String transformQueryParamsInURLFromHydra(String redirectTo) {
71-
try {
72-
URL url = new URL(redirectTo);
73-
String query = url.getQuery();
74-
if (query != null) {
75-
String[] queryParams = query.split("&");
76-
StringBuilder updatedQuery = new StringBuilder();
77-
for (String param : queryParams) {
78-
String[] keyValue = param.split("=");
79-
if (keyValue.length > 1 && keyValue[1].startsWith("ory_")) {
80-
updatedQuery.append(keyValue[0]).append("=").append(keyValue[1].replaceFirst("ory_", "st_")).append("&");
81-
} else {
82-
updatedQuery.append(param).append("&");
83-
}
71+
if (!redirectTo.contains("?")) {
72+
return redirectTo;
73+
}
74+
75+
String query = redirectTo.split("\\?")[1];
76+
if (query != null) {
77+
String[] queryParams = query.split("&");
78+
StringBuilder updatedQuery = new StringBuilder();
79+
for (String param : queryParams) {
80+
String[] keyValue = param.split("=");
81+
if (keyValue.length > 1 && keyValue[1].startsWith("ory_")) {
82+
updatedQuery.append(keyValue[0]).append("=").append(keyValue[1].replaceFirst("ory_", "st_")).append("&");
83+
} else {
84+
updatedQuery.append(param).append("&");
8485
}
85-
redirectTo = redirectTo.replace("?" + query, "?" + updatedQuery.toString().trim());
8686
}
87-
} catch (MalformedURLException e) {
88-
throw new IllegalStateException(e);
87+
redirectTo = redirectTo.replace("?" + query, "?" + updatedQuery.toString().trim());
8988
}
9089

9190
return redirectTo;
@@ -153,37 +152,29 @@ private static String transformRedirectUrlFromHydra(Main main, AppIdentifier app
153152
if (!redirectTo.startsWith("/")) {
154153
redirectTo = transformQueryParamsInURLFromHydra(redirectTo);
155154

156-
try {
157-
if (Utils.containsUrl(redirectTo, hydraInternalAddress, true)) {
158-
try {
159-
URL url = new URL(redirectTo);
160-
String query = url.getQuery();
161-
Map<String, String> urlQueryParams = new HashMap<>();
162-
if (query != null) {
163-
String[] pairs = query.split("&");
164-
for (String pair : pairs) {
165-
int idx = pair.indexOf("=");
166-
urlQueryParams.put(pair.substring(0, idx), URLDecoder.decode(pair.substring(idx + 1), StandardCharsets.UTF_8));
167-
}
168-
}
169-
String error = urlQueryParams.getOrDefault("error", null);
170-
String errorDescription = urlQueryParams.getOrDefault("error_description", null);
171-
if (error != null) {
172-
throw new OAuthAPIException(error, errorDescription, 400);
173-
}
174-
redirectTo = redirectTo.replace(hydraInternalAddress, "{apiDomain}");
175-
176-
// path to hydra starts with /oauth2 while on the SDK it would be /oauth
177-
redirectTo = redirectTo.replace("oauth2/", "oauth/");
178-
179-
} catch (MalformedURLException e) {
180-
throw new IllegalStateException(e);
155+
// We do not use the containsURL util to compare these because redirectTo can be a deep link
156+
// Also, we do not mind comparison to internal addresses being strict comparisons
157+
if (redirectTo.startsWith(hydraInternalAddress)) {
158+
String query = redirectTo.contains("?") ? redirectTo.split("\\?")[1] : null;
159+
Map<String, String> urlQueryParams = new HashMap<>();
160+
if (query != null) {
161+
String[] pairs = query.split("&");
162+
for (String pair : pairs) {
163+
int idx = pair.indexOf("=");
164+
urlQueryParams.put(pair.substring(0, idx), URLDecoder.decode(pair.substring(idx + 1), StandardCharsets.UTF_8));
181165
}
182-
} else if (Utils.containsUrl(redirectTo, hydraBaseUrlForConsentAndLogin, true)) {
183-
redirectTo = redirectTo.replace(hydraBaseUrlForConsentAndLogin, "{apiDomain}");
184166
}
185-
} catch (MalformedURLException e) {
186-
throw new IllegalStateException(e);
167+
String error = urlQueryParams.getOrDefault("error", null);
168+
String errorDescription = urlQueryParams.getOrDefault("error_description", null);
169+
if (error != null) {
170+
throw new OAuthAPIException(error, errorDescription, 400);
171+
}
172+
redirectTo = redirectTo.replace(hydraInternalAddress, "{apiDomain}");
173+
174+
// path to hydra starts with /oauth2 while on the SDK it would be /oauth
175+
redirectTo = redirectTo.replace("oauth2/", "oauth/");
176+
} else if (redirectTo.startsWith(hydraBaseUrlForConsentAndLogin)) {
177+
redirectTo = redirectTo.replace(hydraBaseUrlForConsentAndLogin, "{apiDomain}");
187178
}
188179
}
189180

0 commit comments

Comments
 (0)