Skip to content
This repository was archived by the owner on May 2, 2022. It is now read-only.

Commit 9d41f25

Browse files
authored
Merge pull request #6 from jaxoncreed/fix/NSS#1208
fix/NSS#1208
2 parents f90c55d + b043b68 commit 9d41f25

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

src/SolidClient.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { resolve, parse: parseUrl } = require('url');
1+
const { URL, resolve, parse: parseUrl } = require('url');
22
const https = require('https');
33
const querystring = require('querystring');
44
const RelyingParty = require('@trust/oidc-rp');
@@ -174,8 +174,29 @@ class SolidClient {
174174
}
175175

176176
// Redirect to the authentication page, passing the session cookie
177-
const authUrl = loginResponse.headers.location;
177+
let authUrl = loginResponse.headers.location;
178178
const cookie = loginResponse.headers['set-cookie'][0].replace(/;.*/, '');
179+
180+
// Handle the new consent page in 5.1.1
181+
if (this.isAboveVersion511(loginResponse.headers['x-powered-by'])) {
182+
const consentUrl = new URL(authUrl);
183+
const search = consentUrl.search.substring(1);
184+
let consPostData = JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/\=/g, '":"') + '"}');
185+
consPostData.consent = true;
186+
consPostData.access_mode = ['Read', 'Write', 'Append', 'Control'];
187+
consPostData = querystring.stringify(consPostData);
188+
const consOptions = parseUrl(`${consentUrl.origin}${consentUrl.pathname}`);
189+
consOptions.method = 'POST';
190+
consOptions.headers = {
191+
'Content-Type': 'application/x-www-form-urlencoded',
192+
'Content-Length': consPostData.length,
193+
cookie,
194+
};
195+
const consentResponse = await this.fetch(consOptions, consPostData);
196+
197+
authUrl = consentResponse.headers.location;
198+
}
199+
179200
const authResponse = await this.fetch(Object.assign(parseUrl(authUrl), {
180201
headers: { cookie },
181202
}));
@@ -185,6 +206,10 @@ class SolidClient {
185206
return accessUrl;
186207
}
187208

209+
isAboveVersion511(version) {
210+
return /^solid-server\/5\.(1\.[1-9]|[2-9]|1\d)/.test(version);
211+
}
212+
188213
/**
189214
* Fetches the given resource over HTTP.
190215
*

0 commit comments

Comments
 (0)