@passflow/core 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -9
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -10
- package/dist/index.d.ts +20 -10
- package/dist/index.mjs +376 -303
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -607,6 +607,8 @@ switch (await passflow.getTwoFactorEnrollment()) {
|
|
|
607
607
|
## Token Management
|
|
608
608
|
|
|
609
609
|
```javascript
|
|
610
|
+
import { PassflowEvent } from "@passflow/core";
|
|
611
|
+
|
|
610
612
|
// Check if user is authenticated
|
|
611
613
|
const isAuthenticated = passflow.isAuthenticated();
|
|
612
614
|
|
|
@@ -642,13 +644,28 @@ const setTokens = async (tokens) => {
|
|
|
642
644
|
|
|
643
645
|
// Handle tokens from redirect
|
|
644
646
|
const handleRedirect = () => {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
647
|
+
passflow.subscribe(
|
|
648
|
+
{
|
|
649
|
+
onAuthChange: (event, payload) => {
|
|
650
|
+
if (event === PassflowEvent.SignIn && payload?.source === "tokens-in-url") {
|
|
651
|
+
console.log("Tokens received from redirect", payload.tokens);
|
|
652
|
+
}
|
|
653
|
+
},
|
|
654
|
+
},
|
|
655
|
+
[PassflowEvent.SignIn, PassflowEvent.Error],
|
|
656
|
+
);
|
|
657
|
+
passflow.handleTokensRedirect();
|
|
649
658
|
};
|
|
650
659
|
```
|
|
651
660
|
|
|
661
|
+
`handleTokensRedirect()` returns nothing. It removes the tokens from the URL at once, then
|
|
662
|
+
verifies them in the background before saving them: each signature against the keys at
|
|
663
|
+
`<url>/.well-known/jwks.json`, `iss` against the issuer in `<url>/.well-known/openid-configuration`,
|
|
664
|
+
`aud` against your `appId` (required), `exp`, and the token type. The outcome is `SignIn` with
|
|
665
|
+
`source: "tokens-in-url"`, or `Error` with operation `tokens.from-url` and code `TOKEN_NOT_VERIFIED`
|
|
666
|
+
with nothing saved. Verification needs the Web Crypto API (https or localhost). A federated popup
|
|
667
|
+
that returns tokens in its callback URL is verified the same way.
|
|
668
|
+
|
|
652
669
|
### Token refresh across tabs
|
|
653
670
|
|
|
654
671
|
Every refresh in a `Passflow` instance (`refreshToken()`, `getTokens(true)`,
|
|
@@ -1126,12 +1143,9 @@ document.getElementById("logout-button").addEventListener("click", async () => {
|
|
|
1126
1143
|
// Logout successful - session callback will handle UI update
|
|
1127
1144
|
});
|
|
1128
1145
|
|
|
1129
|
-
// Check for redirect tokens on page load
|
|
1146
|
+
// Check for redirect tokens on page load; SignIn with source "tokens-in-url" reports success
|
|
1130
1147
|
window.addEventListener("load", () => {
|
|
1131
|
-
|
|
1132
|
-
if (tokens) {
|
|
1133
|
-
console.log("Authenticated via redirect");
|
|
1134
|
-
}
|
|
1148
|
+
passflow.handleTokensRedirect();
|
|
1135
1149
|
});
|
|
1136
1150
|
```
|
|
1137
1151
|
|