Skip to content

Commit f53fb56

Browse files
authored
OAuth login refactoring (#257)
* Login with ORCID ID * Refactored OAuth and access requests They have all moved to the end-user dataspace and do not need to extend `GraphStoreImpl` or `SPARQLEndpointImpl` anymore * Commented out secrets * `AuthorizationParams` fix Also fixed access modal form * Test fixes * CORS filter for static assets Context URL fixes * CORS tests * `id_token` is returned via URL fragment Fixed CORS on `/static/` files * Filter out public authorizations * Undo system.trig changes * Removed file
1 parent 8ea7cb6 commit f53fb56

File tree

30 files changed

+1041
-562
lines changed

30 files changed

+1041
-562
lines changed

docker-compose.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ secrets:
55
file: ./secrets/secretary_cert_password.txt
66
client_truststore_password:
77
file: ./secrets/client_truststore_password.txt
8-
#google_client_id:
9-
# file: ./secrets/google_client_id.txt
10-
#google_client_secret:
11-
# file: ./secrets/google_client_secret.txt
8+
# google_client_id:
9+
# file: ./secrets/google/client_id.txt
10+
# google_client_secret:
11+
# file: ./secrets/google/client_secret.txt
12+
# orcid_client_id:
13+
# file: ./secrets/orcid/client_id.txt
14+
# orcid_client_secret:
15+
# file: ./secrets/orcid/client_secret.txt
1216
volumes:
1317
varnish_frontend_cache:
1418
services:
@@ -76,8 +80,10 @@ services:
7680
- owner_cert_password
7781
- secretary_cert_password
7882
- client_truststore_password
79-
#- google_client_id
80-
#- google_client_secret
83+
# - google_client_id
84+
# - google_client_secret
85+
# - orcid_client_id
86+
# - orcid_client_secret
8187
volumes:
8288
- /var/linkeddatahub/oidc
8389
- ./ssl/server:/var/linkeddatahub/ssl/server:ro
@@ -362,6 +368,15 @@ configs:
362368
}
363369
364370
sub vcl_backend_response {
371+
/* Add Vary: Origin for static files to enable proper CORS caching */
372+
if (bereq.url ~ "^/static/") {
373+
if (beresp.http.Vary) {
374+
set beresp.http.Vary = beresp.http.Vary + ", Origin";
375+
} else {
376+
set beresp.http.Vary = "Origin";
377+
}
378+
}
379+
365380
/* purge URLs after updates */
366381
if ((beresp.status == 200 || beresp.status == 201 || beresp.status == 204) && bereq.method ~ "POST|PUT|DELETE|PATCH") {
367382
set beresp.http.X-LinkedDataHub = "Banned";

http-tests/access/POST-request-access.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ curl -w "%{http_code}\n" -o /dev/null -k -s \
3030
--data-urlencode "ol=Access request by Test Agent" \
3131
--data-urlencode "pu=http://www.w3.org/ns/auth/acl#agent" \
3232
--data-urlencode "ou=${AGENT_URI}" \
33-
"${ADMIN_BASE_URL}access/request" \
33+
"${END_USER_BASE_URL}access/request" \
3434
| grep -q "$STATUS_OK"

http-tests/access/group-authorization.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ntriples=$(curl -k -s -G \
1616
-E "$AGENT_CERT_FILE":"$AGENT_CERT_PWD" \
1717
-H "Accept: application/n-triples" \
1818
--data "this=${container}" \
19-
"${ADMIN_BASE_URL}access"
19+
"${END_USER_BASE_URL}access"
2020
)
2121

2222
if echo "$ntriples" | grep -q "<http://www.w3.org/ns/auth/acl#agentGroup> <${ADMIN_BASE_URL}acl/groups/writers/#this>"; then
@@ -47,7 +47,7 @@ ntriples=$(curl -k -s -G \
4747
-E "$AGENT_CERT_FILE":"$AGENT_CERT_PWD" \
4848
-H "Accept: application/n-triples" \
4949
--data "this=${container}" \
50-
"${ADMIN_BASE_URL}access"
50+
"${END_USER_BASE_URL}access"
5151
)
5252

5353
if ! echo "$ntriples" | grep -q "<http://www.w3.org/ns/auth/acl#agentGroup> <${ADMIN_BASE_URL}acl/groups/writers/#this>"; then

http-tests/access/owner-authorization.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ntriples=$(curl -k -s -G \
3333
-E "$AGENT_CERT_FILE":"$AGENT_CERT_PWD" \
3434
-H "Accept: application/n-triples" \
3535
--data "this=${container}" \
36-
"${ADMIN_BASE_URL}access"
36+
"${END_USER_BASE_URL}access"
3737
)
3838

3939
auth1=$(echo "$ntriples" | grep -F "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://w3id.org/atomgraph/linkeddatahub/admin/acl#OwnerAuthorization>" | cut -d' ' -f1)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
initialize_dataset "$END_USER_BASE_URL" "$TMP_END_USER_DATASET" "$END_USER_ENDPOINT_URL"
5+
initialize_dataset "$ADMIN_BASE_URL" "$TMP_ADMIN_DATASET" "$ADMIN_ENDPOINT_URL"
6+
purge_cache "$END_USER_VARNISH_SERVICE"
7+
purge_cache "$ADMIN_VARNISH_SERVICE"
8+
purge_cache "$FRONTEND_VARNISH_SERVICE"
9+
10+
# add agent to the writers group
11+
12+
add-agent-to-group.sh \
13+
-f "$OWNER_CERT_FILE" \
14+
-p "$OWNER_CERT_PWD" \
15+
--agent "$AGENT_URI" \
16+
"${ADMIN_BASE_URL}acl/groups/writers/"
17+
18+
# create container
19+
20+
slug="test-children-query"
21+
22+
container=$(create-container.sh \
23+
-f "$AGENT_CERT_FILE" \
24+
-p "$AGENT_CERT_PWD" \
25+
-b "$END_USER_BASE_URL" \
26+
--title "Test Children Query" \
27+
--slug "$slug" \
28+
--parent "$END_USER_BASE_URL")
29+
30+
# execute SPARQL query to retrieve children of the end-user base URL
31+
32+
query="DESCRIBE * WHERE { SELECT DISTINCT ?child ?thing WHERE { GRAPH ?childGraph { { ?child <http://rdfs.org/sioc/ns#has_parent> <${END_USER_BASE_URL}>. } UNION { ?child <http://rdfs.org/sioc/ns#has_container> <${END_USER_BASE_URL}>. } ?child <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?Type. OPTIONAL { ?child <http://purl.org/dc/terms/title> ?title. } OPTIONAL { ?child <http://xmlns.com/foaf/0.1/primaryTopic> ?thing. } } } ORDER BY (?title) LIMIT 20 }"
33+
34+
curl -k -f -s \
35+
-G \
36+
-E "$AGENT_CERT_FILE":"$AGENT_CERT_PWD" \
37+
-H 'Accept: application/n-triples' \
38+
--data-urlencode "query=$query" \
39+
"${END_USER_BASE_URL}sparql" \
40+
| grep -q "<${container}>"

http-tests/misc/cors-jaxrs.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
initialize_dataset "$END_USER_BASE_URL" "$TMP_END_USER_DATASET" "$END_USER_ENDPOINT_URL"
5+
initialize_dataset "$ADMIN_BASE_URL" "$TMP_ADMIN_DATASET" "$ADMIN_ENDPOINT_URL"
6+
purge_cache "$END_USER_VARNISH_SERVICE"
7+
purge_cache "$ADMIN_VARNISH_SERVICE"
8+
purge_cache "$FRONTEND_VARNISH_SERVICE"
9+
10+
# Test JAX-RS CORSFilter on dynamic content (GET request)
11+
12+
response=$(curl -i -k -s \
13+
-H "Origin: https://example.com" \
14+
-H "Accept: text/turtle" \
15+
"$END_USER_BASE_URL")
16+
17+
# Verify Access-Control-Allow-Origin header is present
18+
if ! echo "$response" | grep -q "Access-Control-Allow-Origin: \*"; then
19+
echo "CORS header 'Access-Control-Allow-Origin' not found in GET response"
20+
exit 1
21+
fi
22+
23+
# Verify Access-Control-Allow-Methods header is present
24+
if ! echo "$response" | grep -q "Access-Control-Allow-Methods:"; then
25+
echo "CORS header 'Access-Control-Allow-Methods' not found in GET response"
26+
exit 1
27+
fi
28+
29+
# Test OPTIONS preflight request
30+
31+
preflight=$(curl -i -k -s \
32+
-X OPTIONS \
33+
-H "Origin: https://example.com" \
34+
-H "Access-Control-Request-Method: POST" \
35+
"$END_USER_BASE_URL")
36+
37+
# Verify preflight response has CORS headers
38+
if ! echo "$preflight" | grep -q "Access-Control-Allow-Origin: \*"; then
39+
echo "CORS header 'Access-Control-Allow-Origin' not found in OPTIONS response"
40+
exit 1
41+
fi
42+
43+
# Verify preflight response has Access-Control-Max-Age
44+
if ! echo "$preflight" | grep -q "Access-Control-Max-Age:"; then
45+
echo "CORS header 'Access-Control-Max-Age' not found in OPTIONS response"
46+
exit 1
47+
fi
48+
49+
# Verify OPTIONS request returns 204 No Content
50+
if ! echo "$preflight" | grep -q "HTTP/.* 204"; then
51+
echo "OPTIONS preflight did not return 204 No Content"
52+
exit 1
53+
fi

http-tests/misc/cors-static.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Test Tomcat CorsFilter on static files
5+
# The Tomcat filter only adds CORS headers when Origin header is present
6+
7+
response=$(curl -i -k -s \
8+
-H "Origin: https://example.com" \
9+
"${END_USER_BASE_URL}static/com/atomgraph/linkeddatahub/css/bootstrap.css")
10+
11+
# Verify Access-Control-Allow-Origin header is present
12+
if ! echo "$response" | grep -q "Access-Control-Allow-Origin: \*"; then
13+
echo "CORS header 'Access-Control-Allow-Origin' not found on static file"
14+
exit 1
15+
fi
16+
17+
# Verify the static file was served successfully
18+
if ! echo "$response" | grep -q "HTTP/.* 200"; then
19+
echo "Static file request did not return 200 OK"
20+
exit 1
21+
fi
22+
23+
# Test OPTIONS request on static files
24+
25+
preflight=$(curl -i -k -s \
26+
-X OPTIONS \
27+
-H "Origin: https://example.com" \
28+
-H "Access-Control-Request-Method: GET" \
29+
"${END_USER_BASE_URL}static/com/atomgraph/linkeddatahub/css/bootstrap.css")
30+
31+
# Verify preflight response has CORS headers
32+
if ! echo "$preflight" | grep -q "Access-Control-Allow-Origin: \*"; then
33+
echo "CORS header 'Access-Control-Allow-Origin' not found in OPTIONS response for static file"
34+
exit 1
35+
fi

platform/context.xsl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
<!ENTITY ac "https://w3id.org/atomgraph/client#">
55
<!ENTITY ldhc "https://w3id.org/atomgraph/linkeddatahub/config#">
66
<!ENTITY google "https://w3id.org/atomgraph/linkeddatahub/services/google#">
7+
<!ENTITY orcid "https://w3id.org/atomgraph/linkeddatahub/services/orcid#">
78
]>
89
<xsl:stylesheet version="1.0"
910
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
1011
xmlns:a="&a;"
1112
xmlns:ac="&ac;"
1213
xmlns:ldhc="&ldhc;"
1314
xmlns:google="&google;"
15+
xmlns:orcid="&orcid;"
1416
>
1517

1618
<xsl:output method="xml" indent="yes"/>
@@ -48,6 +50,8 @@ xmlns:google="&google;"
4850
<xsl:param name="mail.password"/>
4951
<xsl:param name="google:clientID"/>
5052
<xsl:param name="google:clientSecret"/>
53+
<xsl:param name="orcid:clientID"/>
54+
<xsl:param name="orcid:clientSecret"/>
5155

5256
<xsl:template match="@*|node()">
5357
<xsl:copy>
@@ -158,6 +162,12 @@ xmlns:google="&google;"
158162
<xsl:if test="$google:clientSecret">
159163
<Parameter name="&google;clientSecret" value="{$google:clientSecret}" override="false"/>
160164
</xsl:if>
165+
<xsl:if test="$orcid:clientID">
166+
<Parameter name="&orcid;clientID" value="{$orcid:clientID}" override="false"/>
167+
</xsl:if>
168+
<xsl:if test="$orcid:clientSecret">
169+
<Parameter name="&orcid;clientSecret" value="{$orcid:clientSecret}" override="false"/>
170+
</xsl:if>
161171

162172
<xsl:apply-templates select="node()"/>
163173
</xsl:copy>

0 commit comments

Comments
 (0)