@solid/reactive-authentication
v0.1.5
Published
[](https://github.com/solid-contrib/reactive-authentication/actions/workflows/ci.yml?query=branch%3Amain) [ => Promise<string>
// A function that provides an Authorization Server URI based on the original request
let getIssuer: (request: Request) => Promise<URL>Wiring up UI
getCode and getIssuer above can implemented arbitrarily.
But they can also be hooked up to UI elements provided by this library.
If the DOM contains
<authorization-code-flow></authorization-code-flow>
<idp-picker></idp-picker>then the elements provide the required lambdas:
const codeUi = document.querySelector("authorization-code-flow")
const issuerUi = document.querySelector("idp-picker")
getCode = codeUi.getCode.bind(codeUi)
getIssuer = issuerUi.getIssuer.bind(issuerUi)Setup
import { DPoPTokenProvider, ReactiveFetchManager } from "@solid/reactive-authentication"
const provider = new DPoPTokenProvider(callbackUri, getCode, getIssuer)
const manager = new ReactiveFetchManager([provider])Use an authenticated fetch
The ReactiveFetchManager provides a fetch function that can be used to request protected resources:
const response = await manager.fetch(requestUri)Patch global fetch
The ReactiveFetchManager can monkey-patch global fetch to achieve the same effect:
manager.registerGlobally()
const response = await fetch(requestUri)Run the demo
To compile,
npm install
npm run buildThen, for the demo, run a web server on the root folder, e.g.
npx http-serverthen navigate to localhost:8080 (or wherever it was served).
History
The paradigm employed here originates in @langsamu's research project Solid Explorer.
It was later expanded into a robust architecture by @hellikopter and @langsamu in .NET ReactiveAuthentication.
