@solid/reactive-authentication
    Preparing search index...

    @solid/reactive-authentication

    Reactive authentication

    Test Workflow npm

    A reactive authentication library supporting Solid OIDC.

    // The address of the protected resource to be requested
    let requestUri: string

    // The address of a page that users return to after Authoentication Code flow
    let callbackUri: string

    // A function that initiates Authorization Code flow and returns an Authorization Code
    let getCode: (authorizationUri: URL, signal: AbortSignal) => Promise<string>

    // A function that provides an Authorization Server URI based on the original request
    let getIssuer: (request: Request) => Promise<URL>

    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)
    import { DPoPTokenProvider, ReactiveFetchManager } from "@solid/reactive-authentication"

    const provider = new DPoPTokenProvider(callbackUri, getCode, getIssuer)
    const manager = new ReactiveFetchManager([provider])

    The ReactiveFetchManager provides a fetch function that can be used to request protected resources:

    const response = await manager.fetch(requestUri)
    

    The DPoP key is non-extractable and its algorithm comes from the Authorization Server's dpop_signing_alg_values_supported metadata.

    The first supported algorithm in the order ES256, EdDSA, PS256, RS256 is used. If the metadata is absent, ES256 is used. If the server supports none of them, an error is thrown.

    When a response has status 401, the manager parses its WWW-Authenticate challenges and gives them to matches of each provider, in the order of the list. The first provider that matches upgrades the request.

    Provider Matches when a challenge has scheme
    DPoPTokenProvider DPoP or Bearer
    ClientCredentialsTokenProvider DPoP or Bearer
    BearerTokenProvider Bearer

    No provider matches when the header is missing, cannot be parsed or is not exposed to the browser by CORS. Several providers can match the same response, so put the more specific provider earlier in the list.

    To compile,

    npm install
    npm run build

    Then, for the demo, run a web server on the root folder, e.g.

    npx http-server
    

    then navigate to localhost:8080 (or wherever it was served).

    When using this library in Node.js, the minimum supported version is 24.5.

    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.