Skip to content

Commit

Permalink
Add baseURL parameter to support different hosts in Solid auth
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr authored Mar 28, 2023
1 parent b34900d commit 51174cd
Show file tree
Hide file tree
Showing 7 changed files with 1,083 additions and 1,044 deletions.
8 changes: 7 additions & 1 deletion bin/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if (args.h || args.help || args._.length > 1) {
comunica-web-client-generator config/config-default.json -w my-webpack.config.js
Options:
-b The base URL at which the Web Client will be deployed [default: https://query.linkeddatafragments.org/]
-d Destination of the built output (defaults to build)
-m The compilation mode (defaults to production, can also be development)
-c Path to the main Comunica module (defaults to cwd)
Expand All @@ -27,7 +28,7 @@ if (args.h || args.help || args._.length > 1) {
process.exit(1);
}

(async function() {
(async function () {
// Compile JS version of engine to temporary file
const comunicaConfig = args._[0] ? path.resolve(process.cwd(), args._[0]) : path.resolve(__dirname, '..', 'config/config-default.json');
const mainModulePath = args.c || (args._[0] ? process.cwd() : path.resolve(__dirname, '..'));
Expand All @@ -53,7 +54,12 @@ if (args.h || args.help || args._.length > 1) {
// Compile Web version
const destinationPath = args.d || 'build';
const mode = args.m || 'production';
const baseURL = args.b || 'https://query.linkeddatafragments.org/';
const webpackConfig = require(args.w ? path.resolve(process.cwd(), args.w) : '../webpack.config.js');

// Override the baseURL in the webpack config
webpackConfig.baseURL.replace = baseURL;

for (const entry of webpackConfig) {
entry.mode = mode;
if (entry.output) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"index.html",
"settings.json",
"webpack.config.js",
"solid-client-id.json"
"solid-client-id.jsonld"
],
"scripts": {
"lint": "eslint src/*.js",
Expand All @@ -73,6 +73,7 @@
"node-polyfill-webpack-plugin": "^2.0.1",
"rdf-string": "^1.6.1",
"relative-to-absolute-iri": "^1.0.6",
"string-replace-loader": "^3.1.0",
"webpack": "^5.69.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4",
Expand Down
14 changes: 0 additions & 14 deletions solid-client-id.json

This file was deleted.

14 changes: 14 additions & 0 deletions solid-client-id.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"@context": ["https://www.w3.org/ns/solid/oidc-context.jsonld"],
"client_id": "<%= baseURL %>solid-client-id.jsonld",
"client_name": "Comunica Web Client",
"redirect_uris": ["<%= baseURL %>"],
"post_logout_redirect_uris": ["<%= baseURL %>"],
"client_uri": "<%= baseURL %>",
"logo_uri" : "<%= baseURL %>images/logo.svg",
"scope" : "openid profile offline_access webid",
"grant_types" : ["refresh_token","authorization_code"],
"response_types" : ["code"],
"default_max_age" : 3600,
"require_auth_time" : true
}
4 changes: 2 additions & 2 deletions src/ldf-client-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ if (typeof global.process === 'undefined')
else {
$solidSession.login({
oidcIssuer: $idp.val(),
redirectUrl: window.location.href.replace('#', '?'), // OIDC does not allow hash fragments, so we encode it as query param
redirectUrl: '<%= baseURL %>',
clientName: 'Comunica Web Client',
clientId: 'https://query.linkeddatafragments.org/solid-client-id.json',
clientId: '<%= baseURL %>solid-client-id.jsonld',
});
}
return false;
Expand Down
28 changes: 26 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ catch {
comunicaOverride = false;
}

// Make this an object so we can mutate it from the top level of the config
// and have the options propagated to the plugins
const baseURL = {
search: '<%= baseURL %>',
// Default to the localhost for dev mode. The generate.js script should replace this
// value in production mode.
replace: 'http://localhost:8080/',
flags: 'g'
}

module.exports = [
{
entry: [
Expand All @@ -31,7 +41,7 @@ module.exports = [
path.join(__dirname, './images/settings.svg'),
path.join(__dirname, './images/sparql.png'),
path.join(__dirname, './favicon.ico'),
path.join(__dirname, './solid-client-id.json'),
path.join(__dirname, './solid-client-id.jsonld'),
path.join(process.cwd(), './queries.json'),
],
output: {
Expand Down Expand Up @@ -75,11 +85,21 @@ module.exports = [
},
{
type: 'javascript/auto',
test: /solid-client-id\.json$/,
test: /solid-client-id\.jsonld$/,
use: [
{ loader: require.resolve('file-loader'), options: { name: '[name].[ext]' } },
],
},
{
type: 'javascript/auto',
test: /((solid-client-id\.jsonld)|(\.js))$/,
use: [
{
loader: require.resolve('string-replace-loader'),
options: baseURL
},
],
},
{
test: /\.(jpg|png|gif|svg|ico)$/,
use: [
Expand Down Expand Up @@ -138,3 +158,7 @@ module.exports = [
},
},
];

// Export the baseURL object so we can mutated it
// in the generate script
module.exports.baseURL = baseURL;
Loading

0 comments on commit 51174cd

Please sign in to comment.