Skip to content

Commit fc0ec21

Browse files
committed
fix serverlessPod
1 parent 19ef3de commit fc0ec21

File tree

11 files changed

+429
-109
lines changed

11 files changed

+429
-109
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ node_modules
55
test-folder
66
log.txt
77
test.ttl
8-
src/*.js
8+
src/*.js
9+
myPod

dist/cjs/NoAuthSession.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ function () {
1313
options = {};
1414
}
1515

16+
this.fileHandler = options.fileHandler;
17+
this.httpFetch = options.httpFetch;
18+
this.createServerlessPod = this.fileHandler.createServerlessPod.bind(this.fileHandler);
1619
this.session = {
1720
isLoggedIn: false,
1821
info: {
@@ -21,8 +24,6 @@ function () {
2124
fetch: this._fetch.bind(this),
2225
logout: function () {}
2326
};
24-
this.fileHandler = options.fileHandler;
25-
this.httpFetch = options.httpFetch;
2627
}
2728

2829
NoAuthSession.prototype._fetch = function (url, options) {

dist/cjs/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function () {
218218
switch (_a.label) {
219219
case 0:
220220
protocol = new UrlObj.URL(url).protocol.replace(/:$/, '');
221-
_fetch = this.handlers[protocol] && this.handlers[protocol].session ? this.handlers[protocol].session.fetch : this.handlers.fallback && this.handlers.fallback.fetch ? this.handlers.fallback.fetch : this.handlers.file.session.fetch;
221+
_fetch = this.handlers[protocol] && this.handlers[protocol].session ? this.handlers[protocol].session.fetch : this.handlers.file.session.fetch;
222222
return [4
223223
/*yield*/
224224
, _fetch(url.toString(), options)];
@@ -363,9 +363,17 @@ function () {
363363
SolidNodeClient.prototype.createServerlessPod = function (base) {
364364
return __awaiter(this, void 0, void 0, function () {
365365
return __generator(this, function (_a) {
366-
return [2
367-
/*return*/
368-
, this.handlers.fallback.createServerlessPod(base)];
366+
switch (_a.label) {
367+
case 0:
368+
return [4
369+
/*yield*/
370+
, this.handlers.file.createServerlessPod(base)];
371+
372+
case 1:
373+
return [2
374+
/*return*/
375+
, _a.sent()];
376+
}
369377
});
370378
});
371379
};

dist/esm/EssAuthSession.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4+
return new (P || (P = Promise))(function (resolve, reject) {
5+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8+
step((generator = generator.apply(thisArg, _arguments || [])).next());
9+
});
10+
};
11+
var __generator = (this && this.__generator) || function (thisArg, body) {
12+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14+
function verb(n) { return function (v) { return step([n, v]); }; }
15+
function step(op) {
16+
if (f) throw new TypeError("Generator is already executing.");
17+
while (_) try {
18+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19+
if (y = 0, t) op = [op[0] & 2, t.value];
20+
switch (op[0]) {
21+
case 0: case 1: t = op; break;
22+
case 4: _.label++; return { value: op[1], done: false };
23+
case 5: _.label++; y = op[1]; op = [0]; continue;
24+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
25+
default:
26+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30+
if (t[2]) _.ops.pop();
31+
_.trys.pop(); continue;
32+
}
33+
op = body.call(thisArg, _);
34+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36+
}
37+
};
38+
exports.__esModule = true;
39+
exports.EssAuthSession = void 0;
40+
var solid_client_authn_node_1 = require("@inrupt/solid-client-authn-node");
41+
var EssAuthSession = /** @class */ (function () {
42+
function EssAuthSession() {
43+
}
44+
EssAuthSession.prototype.login = function (options) {
45+
return __awaiter(this, void 0, void 0, function () {
46+
var sess;
47+
return __generator(this, function (_a) {
48+
switch (_a.label) {
49+
case 0:
50+
sess = new solid_client_authn_node_1.Session();
51+
return [4 /*yield*/, sess.login({
52+
clientId: options.clientId,
53+
clientSecret: options.clientSecret,
54+
refreshToken: options.refreshToken,
55+
oidcIssuer: options.oidcIssuer
56+
})];
57+
case 1:
58+
_a.sent();
59+
this.session = sess;
60+
this.session.isLoggedIn = sess.info.isLoggedIn;
61+
this.session.webId = sess.info.webId;
62+
return [2 /*return*/, this.session];
63+
}
64+
});
65+
});
66+
};
67+
return EssAuthSession;
68+
}());
69+
exports.EssAuthSession = EssAuthSession;
70+
// ENDS

dist/esm/NoAuthSession.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use strict";
2+
/** UNAUTHENTICATED SESSION
3+
*/
4+
exports.__esModule = true;
5+
exports.NoAuthSession = void 0;
6+
var NoAuthSession = /** @class */ (function () {
7+
function NoAuthSession(options) {
8+
if (options === void 0) { options = {}; }
9+
this.fileHandler = options.fileHandler;
10+
this.httpFetch = options.httpFetch;
11+
this.createServerlessPod = this.fileHandler.createServerlessPod.bind(this.fileHandler);
12+
this.session = {
13+
isLoggedIn: false,
14+
info: { isLoggedIn: false },
15+
fetch: this._fetch.bind(this),
16+
logout: function () { }
17+
};
18+
}
19+
NoAuthSession.prototype._fetch = function (url, options) {
20+
if (url.startsWith('file'))
21+
return this.fileHandler.fetch(url, options);
22+
else
23+
return this.httpFetch(url, options);
24+
};
25+
return NoAuthSession;
26+
}());
27+
exports.NoAuthSession = NoAuthSession;

dist/esm/NssAuthSession.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
"use strict";
2+
/* Login and return session for NSS/PSS via solid-auth-fetcher
3+
*/
4+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6+
return new (P || (P = Promise))(function (resolve, reject) {
7+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10+
step((generator = generator.apply(thisArg, _arguments || [])).next());
11+
});
12+
};
13+
var __generator = (this && this.__generator) || function (thisArg, body) {
14+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
15+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
16+
function verb(n) { return function (v) { return step([n, v]); }; }
17+
function step(op) {
18+
if (f) throw new TypeError("Generator is already executing.");
19+
while (_) try {
20+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
21+
if (y = 0, t) op = [op[0] & 2, t.value];
22+
switch (op[0]) {
23+
case 0: case 1: t = op; break;
24+
case 4: _.label++; return { value: op[1], done: false };
25+
case 5: _.label++; y = op[1]; op = [0]; continue;
26+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
27+
default:
28+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
29+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
30+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
31+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
32+
if (t[2]) _.ops.pop();
33+
_.trys.pop(); continue;
34+
}
35+
op = body.call(thisArg, _);
36+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
37+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
38+
}
39+
};
40+
exports.__esModule = true;
41+
exports.NssAuthSession = void 0;
42+
var solid_auth_fetcher_1 = require("solid-auth-fetcher");
43+
var NssAuthSession = /** @class */ (function () {
44+
function NssAuthSession() {
45+
}
46+
NssAuthSession.prototype.login = function (options) {
47+
return __awaiter(this, void 0, void 0, function () {
48+
var self;
49+
var _this = this;
50+
return __generator(this, function (_a) {
51+
options = options || {};
52+
options.idp = options.idp || process.env.SOLID_IDP || "";
53+
options.username = options.username || process.env.SOLID_USERNAME;
54+
options.password = options.password || process.env.SOLID_PASSWORD;
55+
options.debug = options.debug || (process.env.SOLID_DEBUG) ? true : false;
56+
self = this;
57+
return [2 /*return*/, new Promise(function (resolve, reject) {
58+
_this._getAuthFetcher(options, function (session) {
59+
self.session = session;
60+
resolve(session);
61+
});
62+
})];
63+
});
64+
});
65+
};
66+
NssAuthSession.prototype._getAuthFetcher = function (options, callback) {
67+
return __awaiter(this, void 0, void 0, function () {
68+
var cookie, e_1, _a, session;
69+
var _this = this;
70+
return __generator(this, function (_b) {
71+
switch (_b.label) {
72+
case 0:
73+
_b.trys.push([0, 2, , 3]);
74+
return [4 /*yield*/, solid_auth_fetcher_1.getNodeSolidServerCookie(options.idp, options.username, options.password)];
75+
case 1:
76+
cookie = _b.sent();
77+
return [3 /*break*/, 3];
78+
case 2:
79+
e_1 = _b.sent();
80+
this.authFetcher = null;
81+
return [2 /*return*/, callback(null)];
82+
case 3:
83+
if (!cookie || !cookie.match(/nssidp/)) {
84+
// couldn't login
85+
this.authFetcher = null;
86+
return [2 /*return*/, callback(null)];
87+
}
88+
_a = this;
89+
return [4 /*yield*/, solid_auth_fetcher_1.getAuthFetcher(options.idp, cookie, "https://solid-node-client")];
90+
case 4:
91+
_a.authFetcher = _b.sent();
92+
return [4 /*yield*/, solid_auth_fetcher_1.getSession()];
93+
case 5:
94+
session = _b.sent();
95+
this.authFetcher.onSession(function (s) { return __awaiter(_this, void 0, void 0, function () {
96+
return __generator(this, function (_a) {
97+
s.info = {};
98+
s.info.isLoggedIn = s.isLoggedIn = s.loggedIn;
99+
s.info.webId = s.webId;
100+
s.info.isNss = true;
101+
callback(s);
102+
return [2 /*return*/];
103+
});
104+
}); });
105+
return [2 /*return*/];
106+
}
107+
});
108+
});
109+
};
110+
return NssAuthSession;
111+
}());
112+
exports.NssAuthSession = NssAuthSession;
113+
// ENDS

0 commit comments

Comments
 (0)