Integrate wolfcola devtools with OIDC clients using the OIDC bridge adapter
Generic OIDC Integration
The OIDC bridge adapter instruments OIDC clients that expose their state via an RTK Query-style subscribable store. It maps mutation endpoint results to OIDC protocol phases.
Setup
Install the Bridge
npm install @wolfcola/devtools-bridge
Attach the OIDC Bridge
import { attachOidcBridge } from '@wolfcola/devtools-bridge';
const handle = attachOidcBridge(oidcClient);
// Optionally pass config with clientId and devtools options
const handle = attachOidcBridge(oidcClient, { clientId: 'my-app' }, { consoleLog: true });
The bridge subscribes to the client via client.subscribe() and reads state via client.getState().
Cleanup
handle.detach();
Always call handle.detach() when you are done. Failing to do so may cause memory leaks from lingering event listeners.
What Gets Captured
With the OIDC bridge attached, the following events are emitted:
sdk:config-- Emitted once on the first mutation (whenconfigis provided). Contains the SDK configuration object.sdk:oidc-state-- Emitted for each fulfilled or rejected mutation that maps to a known OIDC endpoint. ContainsOidcDatawith the protocol phase, status, and error details.
How It Works
The bridge monitors RTK Query state at oidc.mutations. It expects an OidcSubscribable interface:
interface OidcSubscribable {
subscribe: (listener: () => void) => () => void;
getState: () => unknown;
}
Endpoint-to-Phase Mapping
The bridge maps RTK Query mutation endpoint names to OIDC protocol phases:
| Endpoint | Phase |
|---|---|
authorizeFetch | authorize |
authorizeIframe | authorize |
exchange | exchange |
revoke | revoke |
userInfo | userinfo |
endSession | logout |
Mutations with endpoint names not in this map are silently ignored.
Processing
On each subscription callback:
- The bridge decodes the state with
Schema.decodeUnknownOptionlooking foroidc.mutations - For each mutation entry not yet emitted, it checks if
statusis'fulfilled'or'rejected' - The
endpointNameis mapped to an OIDC phase - Fulfilled mutations: An
OidcDataevent is emitted withstatus: 'success' - Rejected mutations: An
OidcDataevent is emitted withstatus: 'error', includingerrorCodeanderrorMessageextracted from the error payload - Stale mutation IDs no longer in the cache are automatically pruned from the deduplication set
OidcData Fields
phase:'authorize'|'exchange'|'revoke'|'userinfo'|'logout'status:'success'|'error'clientId: From the config object (if provided)errorCode: Extracted fromerror.data.erroror HTTP statuserrorMessage: Extracted fromerror.data.error_description,error.data.message, orerror.message
Troubleshooting
- No events appearing -- Verify that
window.__PING_DEVTOOLS_EXTENSION__exists. The bridge only emits events when the Ping DevTools extension is detected. - Missing OIDC events -- Only mutations with recognized endpoint names are emitted. Custom endpoints not in the mapping table are ignored.
- Pending mutations ignored -- Only
fulfilledandrejectedmutations are emitted. Pending mutations are skipped.