Skip to content

Commit c22ea7e

Browse files
jeswrrubensworks
authored andcommitted
Add baseURL parameter to support different hosts in Solid auth
1 parent b34900d commit c22ea7e

8 files changed

+1084
-1044
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ comunica-web-client-generator generates Comunica Web clients
8282
comunica-web-client-generator config/config-default.json -w my-webpack.config.js
8383

8484
Options:
85+
-b The base URL at which the Web Client will be deployed [default: https://query.linkeddatafragments.org/]
8586
-d Destination of the built output (defaults to build)
8687
-m The compilation mode (defaults to production, can also be development)
8788
-c Path to the main Comunica module (defaults to cwd)

bin/generate.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if (args.h || args.help || args._.length > 1) {
1616
comunica-web-client-generator config/config-default.json -w my-webpack.config.js
1717
1818
Options:
19+
-b The base URL at which the Web Client will be deployed [default: https://query.linkeddatafragments.org/]
1920
-d Destination of the built output (defaults to build)
2021
-m The compilation mode (defaults to production, can also be development)
2122
-c Path to the main Comunica module (defaults to cwd)
@@ -27,7 +28,7 @@ if (args.h || args.help || args._.length > 1) {
2728
process.exit(1);
2829
}
2930

30-
(async function() {
31+
(async function () {
3132
// Compile JS version of engine to temporary file
3233
const comunicaConfig = args._[0] ? path.resolve(process.cwd(), args._[0]) : path.resolve(__dirname, '..', 'config/config-default.json');
3334
const mainModulePath = args.c || (args._[0] ? process.cwd() : path.resolve(__dirname, '..'));
@@ -53,7 +54,12 @@ if (args.h || args.help || args._.length > 1) {
5354
// Compile Web version
5455
const destinationPath = args.d || 'build';
5556
const mode = args.m || 'production';
57+
const baseURL = args.b || 'https://query.linkeddatafragments.org/';
5658
const webpackConfig = require(args.w ? path.resolve(process.cwd(), args.w) : '../webpack.config.js');
59+
60+
// Override the baseURL in the webpack config
61+
webpackConfig.baseURL.replace = baseURL;
62+
5763
for (const entry of webpackConfig) {
5864
entry.mode = mode;
5965
if (entry.output) {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"index.html",
4848
"settings.json",
4949
"webpack.config.js",
50-
"solid-client-id.json"
50+
"solid-client-id.jsonld"
5151
],
5252
"scripts": {
5353
"lint": "eslint src/*.js",
@@ -73,6 +73,7 @@
7373
"node-polyfill-webpack-plugin": "^2.0.1",
7474
"rdf-string": "^1.6.1",
7575
"relative-to-absolute-iri": "^1.0.6",
76+
"string-replace-loader": "^3.1.0",
7677
"webpack": "^5.69.0",
7778
"webpack-cli": "^4.9.2",
7879
"webpack-dev-server": "^4.7.4",

solid-client-id.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

solid-client-id.jsonld

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"@context": ["https://www.w3.org/ns/solid/oidc-context.jsonld"],
3+
"client_id": "<%= baseURL %>solid-client-id.jsonld",
4+
"client_name": "Comunica Web Client",
5+
"redirect_uris": ["<%= baseURL %>"],
6+
"post_logout_redirect_uris": ["<%= baseURL %>"],
7+
"client_uri": "<%= baseURL %>",
8+
"logo_uri" : "<%= baseURL %>images/logo.svg",
9+
"scope" : "openid profile offline_access webid",
10+
"grant_types" : ["refresh_token","authorization_code"],
11+
"response_types" : ["code"],
12+
"default_max_age" : 3600,
13+
"require_auth_time" : true
14+
}

src/ldf-client-ui.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,9 @@ if (typeof global.process === 'undefined')
352352
else {
353353
$solidSession.login({
354354
oidcIssuer: $idp.val(),
355-
redirectUrl: window.location.href.replace('#', '?'), // OIDC does not allow hash fragments, so we encode it as query param
355+
redirectUrl: '<%= baseURL %>',
356356
clientName: 'Comunica Web Client',
357-
clientId: 'https://query.linkeddatafragments.org/solid-client-id.json',
357+
clientId: '<%= baseURL %>solid-client-id.jsonld',
358358
});
359359
}
360360
return false;

webpack.config.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ catch {
1414
comunicaOverride = false;
1515
}
1616

17+
// Make this an object so we can mutate it from the top level of the config
18+
// and have the options propagated to the plugins
19+
const baseURL = {
20+
search: '<%= baseURL %>',
21+
// Default to the localhost for dev mode. The generate.js script should replace this
22+
// value in production mode.
23+
replace: 'http://localhost:8080/',
24+
flags: 'g'
25+
}
26+
1727
module.exports = [
1828
{
1929
entry: [
@@ -31,7 +41,7 @@ module.exports = [
3141
path.join(__dirname, './images/settings.svg'),
3242
path.join(__dirname, './images/sparql.png'),
3343
path.join(__dirname, './favicon.ico'),
34-
path.join(__dirname, './solid-client-id.json'),
44+
path.join(__dirname, './solid-client-id.jsonld'),
3545
path.join(process.cwd(), './queries.json'),
3646
],
3747
output: {
@@ -75,11 +85,21 @@ module.exports = [
7585
},
7686
{
7787
type: 'javascript/auto',
78-
test: /solid-client-id\.json$/,
88+
test: /solid-client-id\.jsonld$/,
7989
use: [
8090
{ loader: require.resolve('file-loader'), options: { name: '[name].[ext]' } },
8191
],
8292
},
93+
{
94+
type: 'javascript/auto',
95+
test: /((solid-client-id\.jsonld)|(\.js))$/,
96+
use: [
97+
{
98+
loader: require.resolve('string-replace-loader'),
99+
options: baseURL
100+
},
101+
],
102+
},
83103
{
84104
test: /\.(jpg|png|gif|svg|ico)$/,
85105
use: [
@@ -138,3 +158,7 @@ module.exports = [
138158
},
139159
},
140160
];
161+
162+
// Export the baseURL object so we can mutated it
163+
// in the generate script
164+
module.exports.baseURL = baseURL;

0 commit comments

Comments
 (0)