@inrupt/generate-oidc-token
Advanced tools
Comparing version 0.0.1-dependabotgithubactionsactionssetup-node-v214-426655254-10-1608154036.0 to 0.0.1-featinitial-bootstrap-app-426705153-13-1608155778.0
"use strict"; | ||
/** | ||
/* | ||
* Copyright 2020 Inrupt Inc. | ||
@@ -22,7 +22,56 @@ * | ||
*/ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.helloWorld = void 0; | ||
function helloWorld() { | ||
return "hello world!"; | ||
} | ||
exports.helloWorld = helloWorld; | ||
// The only import we need from the Node AuthN library is the Session class. | ||
const solid_client_authn_node_1 = require("@inrupt/solid-client-authn-node"); | ||
const solid_client_authn_core_1 = require("@inrupt/solid-client-authn-core"); | ||
const argv = require("yargs/yargs")(process.argv.slice(2)) | ||
.describe("oidcIssuer", "The identity provider at which the user should authenticate.") | ||
.alias("issuer", "oidcIssuer") | ||
.describe("clientName", "The name of the bootstrapped app.") | ||
.demandOption(["oidcIssuer"]) | ||
.locale("en") | ||
.help().argv; | ||
const express_1 = __importDefault(require("express")); | ||
const app = express_1.default(); | ||
const PORT = 3001; | ||
const iriBase = `http://localhost:${PORT}`; | ||
const storage = new solid_client_authn_core_1.InMemoryStorage(); | ||
// Initialised when the server comes up and is running... | ||
let session; | ||
const server = app.listen(PORT, async () => { | ||
session = new solid_client_authn_node_1.Session({ | ||
insecureStorage: storage, | ||
secureStorage: storage, | ||
}); | ||
console.log(`Listening at: [http://localhost:${PORT}].`); | ||
console.log(`Logging in ${argv.oidcIssuer} to get a refresh token.`); | ||
session.login({ | ||
clientName: argv.clientName, | ||
oidcIssuer: argv.oidcIssuer, | ||
redirectUrl: iriBase, | ||
tokenType: "DPoP", | ||
handleRedirect: (url) => { | ||
console.log(`\nPlease visit ${url} in a web browser.\n`); | ||
}, | ||
}); | ||
}); | ||
app.get("/", async (_req, res) => { | ||
console.log("Login successful."); | ||
await session.handleIncomingRedirect(`${iriBase}${_req.url}`); | ||
// NB: This is a temporary approach, and we have work planned to properly | ||
// collect the token. Please note that the next line is not part of the public | ||
// API, and is therefore likely to break on non-major changes. | ||
const rawStoredSession = await storage.get(`solidClientAuthenticationUser:${session.info.sessionId}`); | ||
if (rawStoredSession === undefined) { | ||
throw new Error(`Cannot find session with ID [${session.info.sessionId}] in storage.`); | ||
} | ||
const storedSession = JSON.parse(rawStoredSession); | ||
console.log(`\nRefresh token: [${storedSession.refreshToken}]`); | ||
console.log(`Client ID: [${storedSession.clientId}]`); | ||
console.log(`Client Secret: [${storedSession.clientSecret}]`); | ||
res.send("The tokens have been sent to the bootstraping app. You can close this window."); | ||
server.close(); | ||
}); |
{ | ||
"name": "@inrupt/generate-oidc-token", | ||
"version": "0.0.1-dependabotgithubactionsactionssetup-node-v214-426655254-10-1608154036.0", | ||
"version": "0.0.1-featinitial-bootstrap-app-426705153-13-1608155778.0", | ||
"description": "A small app to help scripts access private resources on Solid Pods", | ||
@@ -28,2 +28,3 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@types/express": "^4.17.9", | ||
"@types/jest": "^26.0.19", | ||
@@ -51,3 +52,8 @@ "@typescript-eslint/eslint-plugin": "^4.10.0", | ||
}, | ||
"dependencies": {} | ||
"dependencies": { | ||
"@inrupt/solid-client-authn-core": "^1.2.2", | ||
"@inrupt/solid-client-authn-node": "^1.2.2", | ||
"express": "^4.17.1", | ||
"yargs": "^16.2.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
/** | ||
/* | ||
* Copyright 2020 Inrupt Inc. | ||
@@ -22,4 +22,65 @@ * | ||
export function helloWorld() { | ||
return "hello world!"; | ||
} | ||
// The only import we need from the Node AuthN library is the Session class. | ||
import { Session } from "@inrupt/solid-client-authn-node"; | ||
import { InMemoryStorage } from "@inrupt/solid-client-authn-core"; | ||
const argv = require("yargs/yargs")(process.argv.slice(2)) | ||
.describe("oidcIssuer", "The identity provider at which the user should authenticate.") | ||
.alias("issuer", "oidcIssuer") | ||
.describe("clientName", "The name of the bootstrapped app.") | ||
.demandOption(["oidcIssuer"]) | ||
.locale("en") | ||
.help().argv; | ||
import express from "express"; | ||
const app = express(); | ||
const PORT = 3001; | ||
const iriBase = `http://localhost:${PORT}`; | ||
const storage = new InMemoryStorage(); | ||
// Initialised when the server comes up and is running... | ||
let session: Session; | ||
const server = app.listen(PORT, async () => { | ||
session = new Session({ | ||
insecureStorage: storage, | ||
secureStorage: storage, | ||
}); | ||
console.log(`Listening at: [http://localhost:${PORT}].`); | ||
console.log(`Logging in ${argv.oidcIssuer} to get a refresh token.`); | ||
session.login({ | ||
clientName: argv.clientName, | ||
oidcIssuer: argv.oidcIssuer, | ||
redirectUrl: iriBase, | ||
tokenType: "DPoP", | ||
handleRedirect: (url) => { | ||
console.log(`\nPlease visit ${url} in a web browser.\n`); | ||
}, | ||
}); | ||
}); | ||
app.get("/", async (_req, res) => { | ||
console.log("Login successful."); | ||
await session.handleIncomingRedirect(`${iriBase}${_req.url}`); | ||
// NB: This is a temporary approach, and we have work planned to properly | ||
// collect the token. Please note that the next line is not part of the public | ||
// API, and is therefore likely to break on non-major changes. | ||
const rawStoredSession = await storage.get( | ||
`solidClientAuthenticationUser:${session.info.sessionId}` | ||
); | ||
if(rawStoredSession === undefined) { | ||
throw new Error(`Cannot find session with ID [${session.info.sessionId}] in storage.`); | ||
} | ||
const storedSession = JSON.parse(rawStoredSession); | ||
console.log(`\nRefresh token: [${storedSession.refreshToken}]`); | ||
console.log(`Client ID: [${storedSession.clientId}]`); | ||
console.log(`Client Secret: [${storedSession.clientSecret}]`); | ||
res.send( | ||
"The tokens have been sent to the bootstraping app. You can close this window." | ||
); | ||
server.close(); | ||
}); | ||
37708
284
4
13
+ Addedexpress@^4.17.1
+ Addedyargs@^16.2.0
+ Added@fastify/busboy@2.1.1(transitive)
+ Added@inrupt/solid-client-authn-core@1.17.5(transitive)
+ Added@inrupt/solid-client-authn-node@1.17.5(transitive)
+ Added@inrupt/universal-fetch@1.0.3(transitive)
+ Addedaccepts@1.3.8(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedarray-flatten@1.1.1(transitive)
+ Addedbody-parser@1.20.3(transitive)
+ Addedbytes@3.1.2(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedcliui@7.0.4(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcontent-disposition@0.5.4(transitive)
+ Addedcontent-type@1.0.5(transitive)
+ Addedcookie@0.7.1(transitive)
+ Addedcookie-signature@1.0.6(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddepd@2.0.0(transitive)
+ Addeddestroy@1.2.0(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedee-first@1.1.1(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedencodeurl@1.0.22.0.0(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedescape-html@1.0.3(transitive)
+ Addedetag@1.8.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedexpress@4.21.2(transitive)
+ Addedfinalhandler@1.3.1(transitive)
+ Addedforwarded@0.2.0(transitive)
+ Addedfresh@0.5.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhttp-errors@2.0.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedipaddr.js@1.9.1(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedjose@4.15.9(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedmedia-typer@0.3.0(transitive)
+ Addedmerge-descriptors@1.0.3(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.0.02.1.3(transitive)
+ Addednegotiator@0.6.3(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedobject-hash@2.2.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedoidc-token-hash@5.0.3(transitive)
+ Addedon-finished@2.4.1(transitive)
+ Addedopenid-client@5.5.0(transitive)
+ Addedparseurl@1.3.3(transitive)
+ Addedpath-to-regexp@0.1.12(transitive)
+ Addedproxy-addr@2.0.7(transitive)
+ Addedqs@6.13.0(transitive)
+ Addedrange-parser@1.2.1(transitive)
+ Addedraw-body@2.5.2(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsend@0.19.0(transitive)
+ Addedserve-static@1.16.2(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedstatuses@2.0.1(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedtoidentifier@1.0.1(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedtype-is@1.6.18(transitive)
+ Addedundici@5.28.5(transitive)
+ Addedunpipe@1.0.0(transitive)
+ Addedutils-merge@1.0.1(transitive)
+ Addeduuid@9.0.1(transitive)
+ Addedvary@1.1.2(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyallist@4.0.0(transitive)
+ Addedyargs@16.2.0(transitive)
+ Addedyargs-parser@20.2.9(transitive)