lazypock 0.16.0 → 0.16.1
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/dist/index.cjs +21 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -12
- package/dist/index.d.ts +9 -12
- package/dist/index.global.js +21 -28
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +21 -28
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/collection.ts +17 -18
- package/src/oauth2.ts +43 -51
package/dist/index.cjs
CHANGED
|
@@ -641,9 +641,6 @@ function isSafeBrowserUrl(url) {
|
|
|
641
641
|
return false;
|
|
642
642
|
}
|
|
643
643
|
}
|
|
644
|
-
function isRecordAuth(value) {
|
|
645
|
-
return !!value && typeof value === "object" && typeof value.token === "string" && !!value.record && typeof value.record === "object";
|
|
646
|
-
}
|
|
647
644
|
function authorizeWithOAuth2Popup(opts) {
|
|
648
645
|
return new Promise((resolve, reject) => {
|
|
649
646
|
if (typeof window === "undefined") {
|
|
@@ -686,18 +683,20 @@ function authorizeWithOAuth2Popup(opts) {
|
|
|
686
683
|
const data = event.data;
|
|
687
684
|
if (!data || typeof data !== "object") return;
|
|
688
685
|
if (data.type === "lazypock:oauth2") {
|
|
689
|
-
|
|
686
|
+
const code = data.code;
|
|
687
|
+
if (typeof code === "string" && code) {
|
|
690
688
|
if (popup) {
|
|
691
689
|
try {
|
|
692
690
|
popup.close();
|
|
693
691
|
} catch {
|
|
694
692
|
}
|
|
695
693
|
}
|
|
696
|
-
|
|
694
|
+
const state = typeof data.state === "string" ? data.state : void 0;
|
|
695
|
+
finish(null, { code, state });
|
|
697
696
|
} else {
|
|
698
697
|
finish(
|
|
699
698
|
new ApiError(
|
|
700
|
-
"OAuth2 callback returned
|
|
699
|
+
"OAuth2 callback returned no authorization code.",
|
|
701
700
|
data,
|
|
702
701
|
400,
|
|
703
702
|
false,
|
|
@@ -708,16 +707,9 @@ function authorizeWithOAuth2Popup(opts) {
|
|
|
708
707
|
return;
|
|
709
708
|
}
|
|
710
709
|
if (data.type === "lazypock:oauth2:error") {
|
|
711
|
-
const
|
|
712
|
-
const message = typeof result.message === "string" && result.message ? result.message : "OAuth2 authorization failed.";
|
|
710
|
+
const message = typeof data.message === "string" && data.message ? data.message : "OAuth2 authorization failed.";
|
|
713
711
|
finish(
|
|
714
|
-
new ApiError(
|
|
715
|
-
message,
|
|
716
|
-
result,
|
|
717
|
-
typeof result.code === "number" ? result.code : 400,
|
|
718
|
-
false,
|
|
719
|
-
"oauth2_provider_error"
|
|
720
|
-
)
|
|
712
|
+
new ApiError(message, data, 400, false, "oauth2_provider_error")
|
|
721
713
|
);
|
|
722
714
|
}
|
|
723
715
|
};
|
|
@@ -1638,14 +1630,13 @@ var CollectionService = class _CollectionService {
|
|
|
1638
1630
|
/**
|
|
1639
1631
|
* Sign in with an OAuth2 provider (PocketBase `authWithOAuth2` parity).
|
|
1640
1632
|
*
|
|
1641
|
-
* One call handles the whole web flow: fetch the provider's `authURL`,
|
|
1642
|
-
*
|
|
1643
|
-
* `
|
|
1644
|
-
* `{ token, record, meta }`.
|
|
1633
|
+
* One call handles the whole web flow: fetch the provider's `authURL`, open a
|
|
1634
|
+
* popup (or call `options.urlCallback`), receive the single-use authorization
|
|
1635
|
+
* `code` the backend relays via `postMessage`, exchange it, populate the auth
|
|
1636
|
+
* store, and resolve with `{ token, record, meta }`.
|
|
1645
1637
|
*
|
|
1646
|
-
* `options.createData` is
|
|
1647
|
-
*
|
|
1648
|
-
* {@link authWithOAuth2Code} when you need extra fields on first sign-up.
|
|
1638
|
+
* `options.createData` is forwarded on first sign-up (the exchange goes
|
|
1639
|
+
* through {@link authWithOAuth2Code}), matching PocketBase.
|
|
1649
1640
|
*
|
|
1650
1641
|
* React Native / non-browser: the popup flow depends on
|
|
1651
1642
|
* `window.postMessage`. Use {@link listAuthMethods} + {@link authWithOAuth2Code}
|
|
@@ -1654,6 +1645,7 @@ var CollectionService = class _CollectionService {
|
|
|
1654
1645
|
async authWithOAuth2(options) {
|
|
1655
1646
|
const {
|
|
1656
1647
|
provider,
|
|
1648
|
+
createData,
|
|
1657
1649
|
urlCallback,
|
|
1658
1650
|
popup,
|
|
1659
1651
|
timeoutMs = DEFAULT_OAUTH2_TIMEOUT_MS
|
|
@@ -1671,18 +1663,19 @@ var CollectionService = class _CollectionService {
|
|
|
1671
1663
|
"oauth2_unknown_provider"
|
|
1672
1664
|
);
|
|
1673
1665
|
}
|
|
1674
|
-
const
|
|
1666
|
+
const { code } = await authorizeWithOAuth2Popup({
|
|
1675
1667
|
authURL: providerInfo.authURL,
|
|
1676
1668
|
expectedOrigin: oauth2RedirectOrigin(this.http.baseUrl),
|
|
1677
1669
|
urlCallback,
|
|
1678
1670
|
popup,
|
|
1679
1671
|
timeoutMs
|
|
1680
1672
|
});
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1673
|
+
return this.authWithOAuth2Code({
|
|
1674
|
+
provider,
|
|
1675
|
+
code,
|
|
1676
|
+
codeVerifier: providerInfo.codeVerifier,
|
|
1677
|
+
createData
|
|
1678
|
+
});
|
|
1686
1679
|
}
|
|
1687
1680
|
/**
|
|
1688
1681
|
* Exchange an OAuth2 authorization code directly (PocketBase
|