@passflow/core 0.26.0 → 0.28.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 +52 -9
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -11
- package/dist/index.d.ts +29 -11
- package/dist/index.mjs +1185 -1095
- 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)`,
|
|
@@ -837,6 +854,35 @@ try {
|
|
|
837
854
|
}
|
|
838
855
|
```
|
|
839
856
|
|
|
857
|
+
### Service unavailable
|
|
858
|
+
|
|
859
|
+
In a browser, when the Passflow API cannot be reached or its gateway answers 502, 503 or 504 itself,
|
|
860
|
+
an SDK API call rejects with one `PassflowError`:
|
|
861
|
+
|
|
862
|
+
- `id`: `error.service.unavailable`, exported as `SERVICE_UNAVAILABLE_ERROR_ID`
|
|
863
|
+
- `message`: `Passflow is temporarily unavailable. Please try again in a moment.`, exported as
|
|
864
|
+
`SERVICE_UNAVAILABLE_MESSAGE`
|
|
865
|
+
- `status`: the gateway status (502, 503 or 504), or `0` when no answer arrived
|
|
866
|
+
- `cause`: the underlying network error, without the request's config, body or headers
|
|
867
|
+
|
|
868
|
+
```typescript
|
|
869
|
+
import { PassflowError, SERVICE_UNAVAILABLE_ERROR_ID } from "@passflow/core";
|
|
870
|
+
|
|
871
|
+
try {
|
|
872
|
+
await passflow.signIn({ email: "user@example.com", password: "secret" });
|
|
873
|
+
} catch (e) {
|
|
874
|
+
if (e instanceof PassflowError && e.id === SERVICE_UNAVAILABLE_ERROR_ID) {
|
|
875
|
+
showBanner(e.message);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
```
|
|
879
|
+
|
|
880
|
+
It also covers a device that is offline and a request the browser blocked (a gateway answer with no
|
|
881
|
+
CORS headers). The call is not retried; token refresh keeps its own retry schedule. A tab that
|
|
882
|
+
joins another tab's failed token refresh gets `error.refresh.unavailable` instead (see
|
|
883
|
+
[docs/token-refresh.md](docs/token-refresh.md)). An error the Passflow server wrote keeps its own
|
|
884
|
+
id, even with status 503. Calls that wrap their errors in a result object report it in that shape.
|
|
885
|
+
|
|
840
886
|
## API Reference
|
|
841
887
|
|
|
842
888
|
### Passflow Class
|
|
@@ -1126,12 +1172,9 @@ document.getElementById("logout-button").addEventListener("click", async () => {
|
|
|
1126
1172
|
// Logout successful - session callback will handle UI update
|
|
1127
1173
|
});
|
|
1128
1174
|
|
|
1129
|
-
// Check for redirect tokens on page load
|
|
1175
|
+
// Check for redirect tokens on page load; SignIn with source "tokens-in-url" reports success
|
|
1130
1176
|
window.addEventListener("load", () => {
|
|
1131
|
-
|
|
1132
|
-
if (tokens) {
|
|
1133
|
-
console.log("Authenticated via redirect");
|
|
1134
|
-
}
|
|
1177
|
+
passflow.handleTokensRedirect();
|
|
1135
1178
|
});
|
|
1136
1179
|
```
|
|
1137
1180
|
|