isa-auth 0.2.2 → 0.2.3
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 -1
- package/dist/index.d.mts +146 -22
- package/dist/index.d.ts +146 -22
- package/dist/index.js +959 -296
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +958 -296
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7835,20 +7835,32 @@ var require_jwtManager = __commonJS({
|
|
|
7835
7835
|
return (0, _jwtUtils.isExpiredToken)(token, this.clockTolerance);
|
|
7836
7836
|
}
|
|
7837
7837
|
async verifyHmacSha256(token) {
|
|
7838
|
+
var _decoded_header, _globalThis_crypto;
|
|
7838
7839
|
if (!this.secret || !token) return false;
|
|
7839
7840
|
const parts = token.trim().split(".");
|
|
7840
7841
|
if (parts.length !== 3) return false;
|
|
7841
|
-
|
|
7842
|
-
|
|
7842
|
+
const decoded = (0, _jwtUtils.decodeToken)(token);
|
|
7843
|
+
if (!decoded || ((_decoded_header = decoded.header) === null || _decoded_header === void 0 ? void 0 : _decoded_header.alg) !== "HS256") return false;
|
|
7844
|
+
if (this.isExpired(token)) return false;
|
|
7845
|
+
const subtle = typeof globalThis !== "undefined" ? (_globalThis_crypto = globalThis.crypto) === null || _globalThis_crypto === void 0 ? void 0 : _globalThis_crypto.subtle : void 0;
|
|
7846
|
+
if (!subtle) {
|
|
7847
|
+
return false;
|
|
7843
7848
|
}
|
|
7844
7849
|
try {
|
|
7845
7850
|
const enc = new TextEncoder();
|
|
7846
|
-
const key = await
|
|
7851
|
+
const key = await subtle.importKey("raw", enc.encode(this.secret), { name: "HMAC", hash: "SHA-256" }, false, ["verify"]);
|
|
7847
7852
|
let sigBase64 = parts[2].replace(/-/g, "+").replace(/_/g, "/");
|
|
7848
7853
|
while (sigBase64.length % 4 !== 0) sigBase64 += "=";
|
|
7849
|
-
|
|
7854
|
+
let sigBytes;
|
|
7855
|
+
if (typeof atob === "function") {
|
|
7856
|
+
sigBytes = Uint8Array.from(atob(sigBase64), (c) => c.charCodeAt(0));
|
|
7857
|
+
} else if (typeof globalThis.Buffer !== "undefined") {
|
|
7858
|
+
sigBytes = new Uint8Array(globalThis.Buffer.from(sigBase64, "base64"));
|
|
7859
|
+
} else {
|
|
7860
|
+
return false;
|
|
7861
|
+
}
|
|
7850
7862
|
const dataBytes = enc.encode(`${parts[0]}.${parts[1]}`);
|
|
7851
|
-
return await
|
|
7863
|
+
return await subtle.verify("HMAC", key, sigBytes, dataBytes);
|
|
7852
7864
|
} catch {
|
|
7853
7865
|
return false;
|
|
7854
7866
|
}
|
|
@@ -7954,13 +7966,14 @@ var require_guard = __commonJS({
|
|
|
7954
7966
|
if (userPerm === "*" || pattern === "*" || userPerm === pattern) {
|
|
7955
7967
|
return true;
|
|
7956
7968
|
}
|
|
7957
|
-
const
|
|
7969
|
+
const escapeRegexExceptWildcard = (str) => str.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
7970
|
+
const regexStr = "^" + escapeRegexExceptWildcard(pattern) + "$";
|
|
7958
7971
|
try {
|
|
7959
7972
|
const regex = new RegExp(regexStr);
|
|
7960
7973
|
if (regex.test(userPerm)) return true;
|
|
7961
7974
|
} catch {
|
|
7962
7975
|
}
|
|
7963
|
-
const userRegexStr = "^" + userPerm
|
|
7976
|
+
const userRegexStr = "^" + escapeRegexExceptWildcard(userPerm) + "$";
|
|
7964
7977
|
try {
|
|
7965
7978
|
const userRegex = new RegExp(userRegexStr);
|
|
7966
7979
|
if (userRegex.test(pattern)) return true;
|
|
@@ -8123,7 +8136,10 @@ var require_jwtService = __commonJS({
|
|
|
8123
8136
|
(0, _store.setAccessToken)(value);
|
|
8124
8137
|
if (value) {
|
|
8125
8138
|
const payload = this.getAccessTokenPayload();
|
|
8126
|
-
|
|
8139
|
+
if (payload) {
|
|
8140
|
+
const currentInfo = this.getAuthInfo() || {};
|
|
8141
|
+
this.setAuthInfo({ ...currentInfo, ...payload });
|
|
8142
|
+
}
|
|
8127
8143
|
this.setAuthState(true);
|
|
8128
8144
|
if (this.autoRefreshFn) {
|
|
8129
8145
|
this.scheduleNextAutoRefresh();
|
|
@@ -8382,6 +8398,229 @@ var require_service = __commonJS({
|
|
|
8382
8398
|
}
|
|
8383
8399
|
});
|
|
8384
8400
|
|
|
8401
|
+
// ../core/dist/providers/pkce.js
|
|
8402
|
+
var require_pkce = __commonJS({
|
|
8403
|
+
"../core/dist/providers/pkce.js"(exports2) {
|
|
8404
|
+
"use strict";
|
|
8405
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
8406
|
+
function _export(target, all) {
|
|
8407
|
+
for (var name in all) Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get });
|
|
8408
|
+
}
|
|
8409
|
+
_export(exports2, { get buildAuthorizeUrl() {
|
|
8410
|
+
return buildAuthorizeUrl2;
|
|
8411
|
+
}, get generateCodeChallenge() {
|
|
8412
|
+
return generateCodeChallenge2;
|
|
8413
|
+
}, get generateCodeVerifier() {
|
|
8414
|
+
return generateCodeVerifier2;
|
|
8415
|
+
}, get generateRandomState() {
|
|
8416
|
+
return generateRandomState2;
|
|
8417
|
+
}, get handleOAuthCallback() {
|
|
8418
|
+
return handleOAuthCallback2;
|
|
8419
|
+
}, get openOAuthPopup() {
|
|
8420
|
+
return openOAuthPopup2;
|
|
8421
|
+
}, get parseOAuthCallback() {
|
|
8422
|
+
return parseOAuthCallback2;
|
|
8423
|
+
}, get waitForOAuthPopupMessage() {
|
|
8424
|
+
return waitForOAuthPopupMessage2;
|
|
8425
|
+
} });
|
|
8426
|
+
var _jwtUtils = require_jwtUtils();
|
|
8427
|
+
function generateRandomState2(length = 32) {
|
|
8428
|
+
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
8429
|
+
const array = new Uint8Array(length);
|
|
8430
|
+
if (typeof globalThis !== "undefined" && globalThis.crypto && typeof globalThis.crypto.getRandomValues === "function") {
|
|
8431
|
+
globalThis.crypto.getRandomValues(array);
|
|
8432
|
+
} else {
|
|
8433
|
+
for (let i = 0; i < length; i++) {
|
|
8434
|
+
array[i] = Math.floor(Math.random() * 256);
|
|
8435
|
+
}
|
|
8436
|
+
}
|
|
8437
|
+
let result = "";
|
|
8438
|
+
for (let i = 0; i < length; i++) {
|
|
8439
|
+
result += charset[array[i] % charset.length];
|
|
8440
|
+
}
|
|
8441
|
+
return result;
|
|
8442
|
+
}
|
|
8443
|
+
function generateCodeVerifier2(length = 64) {
|
|
8444
|
+
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
8445
|
+
const array = new Uint8Array(length);
|
|
8446
|
+
if (typeof window !== "undefined" && window.crypto) {
|
|
8447
|
+
window.crypto.getRandomValues(array);
|
|
8448
|
+
} else {
|
|
8449
|
+
for (let i = 0; i < length; i++) {
|
|
8450
|
+
array[i] = Math.floor(Math.random() * 256);
|
|
8451
|
+
}
|
|
8452
|
+
}
|
|
8453
|
+
let result = "";
|
|
8454
|
+
for (let i = 0; i < length; i++) {
|
|
8455
|
+
result += charset[array[i] % charset.length];
|
|
8456
|
+
}
|
|
8457
|
+
return result;
|
|
8458
|
+
}
|
|
8459
|
+
async function generateCodeChallenge2(verifier) {
|
|
8460
|
+
if (typeof window !== "undefined" && window.crypto && window.crypto.subtle) {
|
|
8461
|
+
const encoder = new TextEncoder();
|
|
8462
|
+
const data = encoder.encode(verifier);
|
|
8463
|
+
const digest = await window.crypto.subtle.digest("SHA-256", data);
|
|
8464
|
+
const bytes = new Uint8Array(digest);
|
|
8465
|
+
let binary = "";
|
|
8466
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
8467
|
+
binary += String.fromCharCode(bytes[i]);
|
|
8468
|
+
}
|
|
8469
|
+
const base64 = btoa(binary);
|
|
8470
|
+
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
8471
|
+
}
|
|
8472
|
+
return (0, _jwtUtils.base64UrlEncode)(verifier);
|
|
8473
|
+
}
|
|
8474
|
+
function buildAuthorizeUrl2(options) {
|
|
8475
|
+
const { authorizeUrl, clientId, redirectUri, responseType = "code", scope, state, codeChallenge, codeChallengeMethod = "S256", extraParams = {} } = options;
|
|
8476
|
+
const url = new URL(authorizeUrl);
|
|
8477
|
+
url.searchParams.set("client_id", clientId);
|
|
8478
|
+
url.searchParams.set("redirect_uri", redirectUri);
|
|
8479
|
+
url.searchParams.set("response_type", responseType);
|
|
8480
|
+
if (scope) url.searchParams.set("scope", scope);
|
|
8481
|
+
if (state) url.searchParams.set("state", state);
|
|
8482
|
+
if (codeChallenge) {
|
|
8483
|
+
url.searchParams.set("code_challenge", codeChallenge);
|
|
8484
|
+
url.searchParams.set("code_challenge_method", codeChallengeMethod);
|
|
8485
|
+
}
|
|
8486
|
+
for (const [key, value] of Object.entries(extraParams)) {
|
|
8487
|
+
url.searchParams.set(key, value);
|
|
8488
|
+
}
|
|
8489
|
+
return url.toString();
|
|
8490
|
+
}
|
|
8491
|
+
function parseOAuthCallback2(urlOrSearch) {
|
|
8492
|
+
const result = {};
|
|
8493
|
+
const parseString = (str) => {
|
|
8494
|
+
if (!str) return;
|
|
8495
|
+
const cleaned = str.replace(/^[?#&]+/, "");
|
|
8496
|
+
if (!cleaned) return;
|
|
8497
|
+
const params = new URLSearchParams(cleaned);
|
|
8498
|
+
params.forEach((val, key) => {
|
|
8499
|
+
result[key] = val;
|
|
8500
|
+
});
|
|
8501
|
+
};
|
|
8502
|
+
if (urlOrSearch) {
|
|
8503
|
+
if (/^https?:\/\//i.test(urlOrSearch)) {
|
|
8504
|
+
try {
|
|
8505
|
+
const parsedUrl = new URL(urlOrSearch);
|
|
8506
|
+
if (parsedUrl.search) {
|
|
8507
|
+
parseString(parsedUrl.search);
|
|
8508
|
+
}
|
|
8509
|
+
if (parsedUrl.hash) {
|
|
8510
|
+
parseString(parsedUrl.hash);
|
|
8511
|
+
}
|
|
8512
|
+
} catch {
|
|
8513
|
+
}
|
|
8514
|
+
} else if (urlOrSearch.includes("?")) {
|
|
8515
|
+
const parts = urlOrSearch.split("?");
|
|
8516
|
+
const queryAndHash = parts[1] || "";
|
|
8517
|
+
if (queryAndHash.includes("#")) {
|
|
8518
|
+
const [query, hash] = queryAndHash.split("#");
|
|
8519
|
+
parseString(query);
|
|
8520
|
+
parseString(hash);
|
|
8521
|
+
} else {
|
|
8522
|
+
parseString(queryAndHash);
|
|
8523
|
+
}
|
|
8524
|
+
} else if (urlOrSearch.includes("#")) {
|
|
8525
|
+
parseString(urlOrSearch.split("#")[1]);
|
|
8526
|
+
} else {
|
|
8527
|
+
parseString(urlOrSearch);
|
|
8528
|
+
}
|
|
8529
|
+
} else if (typeof window !== "undefined") {
|
|
8530
|
+
if (window.location.search) {
|
|
8531
|
+
parseString(window.location.search);
|
|
8532
|
+
}
|
|
8533
|
+
if (window.location.hash) {
|
|
8534
|
+
parseString(window.location.hash);
|
|
8535
|
+
}
|
|
8536
|
+
}
|
|
8537
|
+
if (result.access_token && !result.token) {
|
|
8538
|
+
result.token = result.access_token;
|
|
8539
|
+
}
|
|
8540
|
+
return result;
|
|
8541
|
+
}
|
|
8542
|
+
function handleOAuthCallback2(options) {
|
|
8543
|
+
const result = parseOAuthCallback2(options === null || options === void 0 ? void 0 : options.urlOrSearch);
|
|
8544
|
+
if (typeof window !== "undefined") {
|
|
8545
|
+
if ((options === null || options === void 0 ? void 0 : options.storageKey) && window.sessionStorage) {
|
|
8546
|
+
try {
|
|
8547
|
+
window.sessionStorage.setItem(options.storageKey, JSON.stringify(result));
|
|
8548
|
+
} catch (e) {
|
|
8549
|
+
}
|
|
8550
|
+
}
|
|
8551
|
+
if (window.opener && typeof window.opener.postMessage === "function") {
|
|
8552
|
+
const targetOrigin = (options === null || options === void 0 ? void 0 : options.targetOrigin) || window.location.origin;
|
|
8553
|
+
window.opener.postMessage({ type: "ISA_AUTH_OAUTH_CALLBACK", payload: result }, targetOrigin);
|
|
8554
|
+
if ((options === null || options === void 0 ? void 0 : options.closePopup) !== false) {
|
|
8555
|
+
window.close();
|
|
8556
|
+
}
|
|
8557
|
+
}
|
|
8558
|
+
}
|
|
8559
|
+
return result;
|
|
8560
|
+
}
|
|
8561
|
+
function openOAuthPopup2(url, title = "isa_auth_oauth_login", width = 500, height = 650) {
|
|
8562
|
+
if (typeof window === "undefined") return null;
|
|
8563
|
+
const left = window.screenX + Math.max(0, (window.outerWidth - width) / 2);
|
|
8564
|
+
const top = window.screenY + Math.max(0, (window.outerHeight - height) / 2);
|
|
8565
|
+
const popup = window.open(url, title, `width=${width},height=${height},left=${left},top=${top},status=no,resizable=yes,scrollbars=yes`);
|
|
8566
|
+
return popup;
|
|
8567
|
+
}
|
|
8568
|
+
function waitForOAuthPopupMessage2(popup, timeoutMsOrOptions = 12e4) {
|
|
8569
|
+
const opts = typeof timeoutMsOrOptions === "number" ? { timeoutMs: timeoutMsOrOptions } : timeoutMsOrOptions || {};
|
|
8570
|
+
var _opts_timeoutMs;
|
|
8571
|
+
const timeoutMs = (_opts_timeoutMs = opts.timeoutMs) !== null && _opts_timeoutMs !== void 0 ? _opts_timeoutMs : 12e4;
|
|
8572
|
+
var _opts_expectedOrigin;
|
|
8573
|
+
const expectedOrigin = (_opts_expectedOrigin = opts.expectedOrigin) !== null && _opts_expectedOrigin !== void 0 ? _opts_expectedOrigin : typeof window !== "undefined" && window.location ? window.location.origin : "*";
|
|
8574
|
+
const expectedState = opts.expectedState;
|
|
8575
|
+
return new Promise((resolve, reject) => {
|
|
8576
|
+
if (typeof window === "undefined") {
|
|
8577
|
+
return reject(new Error("Window is undefined"));
|
|
8578
|
+
}
|
|
8579
|
+
if (!popup) {
|
|
8580
|
+
return reject(new Error("Popup blocked or failed to open"));
|
|
8581
|
+
}
|
|
8582
|
+
let timer = null;
|
|
8583
|
+
let checkClosedInterval = null;
|
|
8584
|
+
const cleanup = () => {
|
|
8585
|
+
if (timer) clearTimeout(timer);
|
|
8586
|
+
if (checkClosedInterval) clearInterval(checkClosedInterval);
|
|
8587
|
+
window.removeEventListener("message", handleMessage);
|
|
8588
|
+
};
|
|
8589
|
+
const handleMessage = (event) => {
|
|
8590
|
+
if (expectedOrigin !== "*" && event.origin !== expectedOrigin) {
|
|
8591
|
+
return;
|
|
8592
|
+
}
|
|
8593
|
+
if (event.source && event.source !== popup) {
|
|
8594
|
+
return;
|
|
8595
|
+
}
|
|
8596
|
+
if (event.data && event.data.type === "ISA_AUTH_OAUTH_CALLBACK") {
|
|
8597
|
+
cleanup();
|
|
8598
|
+
const payload = event.data.payload || {};
|
|
8599
|
+
if (expectedState && payload.state !== expectedState) {
|
|
8600
|
+
reject(new Error("OAuth state mismatch (possible CSRF attack)"));
|
|
8601
|
+
} else if (payload.error) {
|
|
8602
|
+
reject(new Error(payload.error_description || payload.error));
|
|
8603
|
+
} else {
|
|
8604
|
+
resolve(payload);
|
|
8605
|
+
}
|
|
8606
|
+
}
|
|
8607
|
+
};
|
|
8608
|
+
window.addEventListener("message", handleMessage);
|
|
8609
|
+
checkClosedInterval = setInterval(() => {
|
|
8610
|
+
if (popup.closed) {
|
|
8611
|
+
cleanup();
|
|
8612
|
+
reject(new Error("Popup was closed by user before completing authentication"));
|
|
8613
|
+
}
|
|
8614
|
+
}, 500);
|
|
8615
|
+
timer = setTimeout(() => {
|
|
8616
|
+
cleanup();
|
|
8617
|
+
reject(new Error(`OAuth authentication timed out after ${timeoutMs}ms`));
|
|
8618
|
+
}, timeoutMs);
|
|
8619
|
+
});
|
|
8620
|
+
}
|
|
8621
|
+
}
|
|
8622
|
+
});
|
|
8623
|
+
|
|
8385
8624
|
// ../core/dist/providers/social/googleAuth.js
|
|
8386
8625
|
var require_googleAuth = __commonJS({
|
|
8387
8626
|
"../core/dist/providers/social/googleAuth.js"(exports2) {
|
|
@@ -8396,6 +8635,8 @@ var require_googleAuth = __commonJS({
|
|
|
8396
8635
|
return _default;
|
|
8397
8636
|
} });
|
|
8398
8637
|
var _isautil = require_dist();
|
|
8638
|
+
var _jwtUtils = require_jwtUtils();
|
|
8639
|
+
var _pkce = require_pkce();
|
|
8399
8640
|
function _define_property(obj, key, value) {
|
|
8400
8641
|
if (key in obj) {
|
|
8401
8642
|
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
@@ -8406,29 +8647,128 @@ var require_googleAuth = __commonJS({
|
|
|
8406
8647
|
}
|
|
8407
8648
|
var GoogleAuthProvider2 = class {
|
|
8408
8649
|
async loadGoogleSdk() {
|
|
8409
|
-
|
|
8410
|
-
if (typeof window !== "undefined" && window.google && ((_window_google_accounts = window.google.accounts) === null || _window_google_accounts === void 0 ? void 0 : _window_google_accounts.id)) {
|
|
8650
|
+
if (typeof window !== "undefined" && window.google && window.google.accounts) {
|
|
8411
8651
|
return;
|
|
8412
8652
|
}
|
|
8413
8653
|
await (0, _isautil.loadCDN)("google-gsi", "https://accounts.google.com/gsi/client", { async: true, defer: true });
|
|
8414
8654
|
}
|
|
8415
8655
|
async init() {
|
|
8416
|
-
|
|
8417
|
-
if (typeof window
|
|
8656
|
+
var _window_google_accounts, _window_google, _window_google_accounts1, _window_google1;
|
|
8657
|
+
if (typeof window === "undefined") return;
|
|
8658
|
+
try {
|
|
8659
|
+
await this.loadGoogleSdk();
|
|
8660
|
+
} catch {
|
|
8661
|
+
return;
|
|
8662
|
+
}
|
|
8663
|
+
if ((_window_google = window.google) === null || _window_google === void 0 ? void 0 : (_window_google_accounts = _window_google.accounts) === null || _window_google_accounts === void 0 ? void 0 : _window_google_accounts.id) {
|
|
8418
8664
|
window.google.accounts.id.initialize({ client_id: this.clientId, callback: (response) => {
|
|
8419
|
-
|
|
8665
|
+
if (response === null || response === void 0 ? void 0 : response.credential) {
|
|
8666
|
+
this.handleCredentialResponse(response.credential);
|
|
8667
|
+
}
|
|
8420
8668
|
} });
|
|
8669
|
+
if (this.autoPrompt) {
|
|
8670
|
+
window.google.accounts.id.prompt();
|
|
8671
|
+
}
|
|
8672
|
+
}
|
|
8673
|
+
if ((_window_google1 = window.google) === null || _window_google1 === void 0 ? void 0 : (_window_google_accounts1 = _window_google1.accounts) === null || _window_google_accounts1 === void 0 ? void 0 : _window_google_accounts1.oauth2) {
|
|
8674
|
+
try {
|
|
8675
|
+
this.tokenClient = window.google.accounts.oauth2.initTokenClient({ client_id: this.clientId, scope: this.scope, callback: async (tokenResponse) => {
|
|
8676
|
+
const pending = this.pendingSignIn;
|
|
8677
|
+
this.pendingSignIn = null;
|
|
8678
|
+
if (tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.error) {
|
|
8679
|
+
if (this.onFail) this.onFail(tokenResponse);
|
|
8680
|
+
if (pending) pending.reject(tokenResponse);
|
|
8681
|
+
return;
|
|
8682
|
+
}
|
|
8683
|
+
this.accessToken = tokenResponse.access_token;
|
|
8684
|
+
try {
|
|
8685
|
+
const res = await fetch("https://www.googleapis.com/oauth2/v3/userinfo", { headers: { Authorization: `Bearer ${tokenResponse.access_token}` } });
|
|
8686
|
+
if (res.ok) {
|
|
8687
|
+
this.userInfo = await res.json();
|
|
8688
|
+
}
|
|
8689
|
+
} catch (e) {
|
|
8690
|
+
}
|
|
8691
|
+
if (this.callback) await this.callback(tokenResponse.access_token);
|
|
8692
|
+
if (this.onSuccess) this.onSuccess(this.userInfo || tokenResponse);
|
|
8693
|
+
if (pending) pending.resolve();
|
|
8694
|
+
}, error_callback: (err) => {
|
|
8695
|
+
const pending = this.pendingSignIn;
|
|
8696
|
+
this.pendingSignIn = null;
|
|
8697
|
+
if (this.onFail) this.onFail(err);
|
|
8698
|
+
if (pending) pending.reject(err);
|
|
8699
|
+
} });
|
|
8700
|
+
} catch (err) {
|
|
8701
|
+
}
|
|
8421
8702
|
}
|
|
8422
8703
|
}
|
|
8423
|
-
|
|
8424
|
-
|
|
8704
|
+
handleCredentialResponse(credential) {
|
|
8705
|
+
this.idToken = credential;
|
|
8706
|
+
const decoded = (0, _jwtUtils.decodeToken)(credential);
|
|
8707
|
+
if (decoded === null || decoded === void 0 ? void 0 : decoded.payload) {
|
|
8708
|
+
this.userInfo = decoded.payload;
|
|
8709
|
+
}
|
|
8710
|
+
if (this.callback) {
|
|
8711
|
+
this.callback(credential);
|
|
8712
|
+
}
|
|
8713
|
+
if (this.onSuccess) {
|
|
8714
|
+
this.onSuccess(this.userInfo || { id_token: credential });
|
|
8715
|
+
}
|
|
8716
|
+
}
|
|
8717
|
+
promptOneTap() {
|
|
8718
|
+
var _window_google_accounts, _window_google;
|
|
8719
|
+
if (typeof window !== "undefined" && ((_window_google = window.google) === null || _window_google === void 0 ? void 0 : (_window_google_accounts = _window_google.accounts) === null || _window_google_accounts === void 0 ? void 0 : _window_google_accounts.id)) {
|
|
8425
8720
|
window.google.accounts.id.prompt();
|
|
8721
|
+
}
|
|
8722
|
+
}
|
|
8723
|
+
renderGoogleButton(parent, options) {
|
|
8724
|
+
var _window_google_accounts, _window_google;
|
|
8725
|
+
if (typeof window !== "undefined" && ((_window_google = window.google) === null || _window_google === void 0 ? void 0 : (_window_google_accounts = _window_google.accounts) === null || _window_google_accounts === void 0 ? void 0 : _window_google_accounts.id)) {
|
|
8726
|
+
window.google.accounts.id.renderButton(parent, options || { theme: "outline", size: "large" });
|
|
8727
|
+
}
|
|
8728
|
+
}
|
|
8729
|
+
async signIn() {
|
|
8730
|
+
var _window_google_accounts, _window_google;
|
|
8731
|
+
if (typeof window === "undefined") return;
|
|
8732
|
+
if (this.tokenClient && typeof this.tokenClient.requestAccessToken === "function") {
|
|
8733
|
+
return new Promise((resolve, reject) => {
|
|
8734
|
+
this.pendingSignIn = { resolve, reject };
|
|
8735
|
+
this.tokenClient.requestAccessToken({ prompt: "consent" });
|
|
8736
|
+
});
|
|
8737
|
+
}
|
|
8738
|
+
if ((_window_google = window.google) === null || _window_google === void 0 ? void 0 : (_window_google_accounts = _window_google.accounts) === null || _window_google_accounts === void 0 ? void 0 : _window_google_accounts.id) {
|
|
8739
|
+
window.google.accounts.id.prompt();
|
|
8740
|
+
return;
|
|
8741
|
+
}
|
|
8742
|
+
const state = (0, _pkce.generateRandomState)();
|
|
8743
|
+
const authUrl = (0, _pkce.buildAuthorizeUrl)({ authorizeUrl: "https://accounts.google.com/o/oauth2/v2/auth", clientId: this.clientId, redirectUri: this.redirectUri || window.location.origin, responseType: "token id_token", scope: this.scope, state, extraParams: { nonce: (0, _pkce.generateRandomState)() } });
|
|
8744
|
+
if (this.isPopup) {
|
|
8745
|
+
const popup = (0, _pkce.openOAuthPopup)(authUrl, "google_login");
|
|
8746
|
+
if (!popup) {
|
|
8747
|
+
window.location.href = authUrl;
|
|
8748
|
+
return;
|
|
8749
|
+
}
|
|
8750
|
+
try {
|
|
8751
|
+
const callbackResult = await (0, _pkce.waitForOAuthPopupMessage)(popup, { expectedState: state });
|
|
8752
|
+
if (callbackResult.access_token) {
|
|
8753
|
+
this.accessToken = callbackResult.access_token;
|
|
8754
|
+
}
|
|
8755
|
+
if (callbackResult.id_token) {
|
|
8756
|
+
this.handleCredentialResponse(callbackResult.id_token);
|
|
8757
|
+
}
|
|
8758
|
+
} catch (err) {
|
|
8759
|
+
if (this.onFail) this.onFail(err);
|
|
8760
|
+
}
|
|
8426
8761
|
} else {
|
|
8427
|
-
|
|
8762
|
+
window.location.href = authUrl;
|
|
8428
8763
|
}
|
|
8429
8764
|
}
|
|
8430
8765
|
signOut() {
|
|
8431
8766
|
var _window_google;
|
|
8767
|
+
const tokenToRevoke = this.accessToken;
|
|
8768
|
+
this.accessToken = null;
|
|
8769
|
+
this.idToken = null;
|
|
8770
|
+
this.userInfo = null;
|
|
8771
|
+
this.pendingSignIn = null;
|
|
8432
8772
|
if (typeof window !== "undefined" && ((_window_google = window.google) === null || _window_google === void 0 ? void 0 : _window_google.accounts)) {
|
|
8433
8773
|
try {
|
|
8434
8774
|
var _window_google_accounts_id;
|
|
@@ -8439,38 +8779,45 @@ var require_googleAuth = __commonJS({
|
|
|
8439
8779
|
}
|
|
8440
8780
|
try {
|
|
8441
8781
|
var _window_google_accounts_oauth2;
|
|
8442
|
-
if (typeof ((_window_google_accounts_oauth2 = window.google.accounts.oauth2) === null || _window_google_accounts_oauth2 === void 0 ? void 0 : _window_google_accounts_oauth2.
|
|
8443
|
-
window.google.accounts.oauth2.
|
|
8782
|
+
if (typeof ((_window_google_accounts_oauth2 = window.google.accounts.oauth2) === null || _window_google_accounts_oauth2 === void 0 ? void 0 : _window_google_accounts_oauth2.revoke) === "function" && tokenToRevoke) {
|
|
8783
|
+
window.google.accounts.oauth2.revoke(tokenToRevoke, () => {
|
|
8784
|
+
});
|
|
8444
8785
|
}
|
|
8445
8786
|
} catch (e) {
|
|
8446
8787
|
}
|
|
8447
8788
|
}
|
|
8448
8789
|
}
|
|
8449
8790
|
async getAccessToken() {
|
|
8450
|
-
|
|
8451
|
-
if (typeof window !== "undefined" && ((_window_google = window.google) === null || _window_google === void 0 ? void 0 : (_window_google_accounts = _window_google.accounts) === null || _window_google_accounts === void 0 ? void 0 : _window_google_accounts.oauth2)) {
|
|
8452
|
-
if (typeof window.google.accounts.oauth2.getAccessToken === "function") {
|
|
8453
|
-
const token = await window.google.accounts.oauth2.getAccessToken();
|
|
8454
|
-
return token;
|
|
8455
|
-
}
|
|
8456
|
-
}
|
|
8457
|
-
return null;
|
|
8791
|
+
return this.accessToken || this.idToken || null;
|
|
8458
8792
|
}
|
|
8459
8793
|
async getUserInfo() {
|
|
8460
|
-
|
|
8461
|
-
if (typeof window !== "undefined" && ((_window_google = window.google) === null || _window_google === void 0 ? void 0 : (_window_google_accounts = _window_google.accounts) === null || _window_google_accounts === void 0 ? void 0 : _window_google_accounts.id)) {
|
|
8462
|
-
if (typeof window.google.accounts.id.getUserInfo === "function") {
|
|
8463
|
-
const user = await window.google.accounts.id.getUserInfo();
|
|
8464
|
-
return user;
|
|
8465
|
-
}
|
|
8466
|
-
}
|
|
8467
|
-
return null;
|
|
8794
|
+
return this.userInfo || null;
|
|
8468
8795
|
}
|
|
8469
|
-
constructor(
|
|
8796
|
+
constructor(options) {
|
|
8470
8797
|
_define_property(this, "clientId", void 0);
|
|
8471
8798
|
_define_property(this, "callback", void 0);
|
|
8472
|
-
this
|
|
8473
|
-
this
|
|
8799
|
+
_define_property(this, "scope", void 0);
|
|
8800
|
+
_define_property(this, "autoPrompt", void 0);
|
|
8801
|
+
_define_property(this, "redirectUri", void 0);
|
|
8802
|
+
_define_property(this, "isPopup", void 0);
|
|
8803
|
+
_define_property(this, "onSuccess", void 0);
|
|
8804
|
+
_define_property(this, "onFail", void 0);
|
|
8805
|
+
_define_property(this, "idToken", null);
|
|
8806
|
+
_define_property(this, "accessToken", null);
|
|
8807
|
+
_define_property(this, "userInfo", null);
|
|
8808
|
+
_define_property(this, "tokenClient", null);
|
|
8809
|
+
_define_property(this, "pendingSignIn", null);
|
|
8810
|
+
this.clientId = options.clientId;
|
|
8811
|
+
this.callback = options.callback;
|
|
8812
|
+
const opts = options;
|
|
8813
|
+
this.scope = opts.scope || "openid email profile";
|
|
8814
|
+
var _opts_autoPrompt;
|
|
8815
|
+
this.autoPrompt = (_opts_autoPrompt = opts.autoPrompt) !== null && _opts_autoPrompt !== void 0 ? _opts_autoPrompt : false;
|
|
8816
|
+
this.redirectUri = opts.redirectUri;
|
|
8817
|
+
var _opts_isPopup;
|
|
8818
|
+
this.isPopup = (_opts_isPopup = opts.isPopup) !== null && _opts_isPopup !== void 0 ? _opts_isPopup : true;
|
|
8819
|
+
this.onSuccess = opts.onSuccess;
|
|
8820
|
+
this.onFail = opts.onFail;
|
|
8474
8821
|
}
|
|
8475
8822
|
};
|
|
8476
8823
|
var _default = GoogleAuthProvider2;
|
|
@@ -8491,6 +8838,8 @@ var require_appleAuth = __commonJS({
|
|
|
8491
8838
|
return _default;
|
|
8492
8839
|
} });
|
|
8493
8840
|
var _isautil = require_dist();
|
|
8841
|
+
var _jwtUtils = require_jwtUtils();
|
|
8842
|
+
var _pkce = require_pkce();
|
|
8494
8843
|
function _define_property(obj, key, value) {
|
|
8495
8844
|
if (key in obj) {
|
|
8496
8845
|
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
@@ -8508,149 +8857,118 @@ var require_appleAuth = __commonJS({
|
|
|
8508
8857
|
}
|
|
8509
8858
|
async init() {
|
|
8510
8859
|
if (typeof window === "undefined") return;
|
|
8511
|
-
|
|
8512
|
-
|
|
8513
|
-
window.AppleID
|
|
8860
|
+
try {
|
|
8861
|
+
await this.loadAppleSdk();
|
|
8862
|
+
if (window.AppleID && window.AppleID.auth) {
|
|
8863
|
+
window.AppleID.auth.init({ clientId: this.clientId, scope: this.scope, redirectURI: this.redirectURI, state: this.state || Math.random().toString(36).substring(2, 15), nonce: this.nonce, usePopup: this.usePopup });
|
|
8864
|
+
}
|
|
8865
|
+
} catch (e) {
|
|
8514
8866
|
}
|
|
8515
8867
|
}
|
|
8868
|
+
buildAuthUrl() {
|
|
8869
|
+
const state = this.state || (0, _pkce.generateRandomState)();
|
|
8870
|
+
this.lastState = state;
|
|
8871
|
+
const requestsUserFields = /\b(name|email)\b/.test(this.scope);
|
|
8872
|
+
const responseMode = this.responseMode || (requestsUserFields ? "form_post" : "fragment");
|
|
8873
|
+
return (0, _pkce.buildAuthorizeUrl)({ authorizeUrl: "https://appleid.apple.com/auth/authorize", clientId: this.clientId, redirectUri: this.redirectURI, responseType: "code id_token", scope: this.scope, state, extraParams: { response_mode: responseMode, ...this.nonce ? { nonce: this.nonce } : {} } });
|
|
8874
|
+
}
|
|
8516
8875
|
async signIn() {
|
|
8517
8876
|
if (typeof window === "undefined") return;
|
|
8518
|
-
if (
|
|
8519
|
-
|
|
8520
|
-
|
|
8521
|
-
|
|
8522
|
-
|
|
8523
|
-
|
|
8524
|
-
|
|
8525
|
-
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
|
|
8877
|
+
if (window.AppleID && window.AppleID.auth) {
|
|
8878
|
+
try {
|
|
8879
|
+
const response = await window.AppleID.auth.signIn();
|
|
8880
|
+
if (response && response.authorization) {
|
|
8881
|
+
this.idToken = response.authorization.id_token;
|
|
8882
|
+
this.userInfo = response.user || null;
|
|
8883
|
+
if (!this.userInfo && this.idToken) {
|
|
8884
|
+
const decoded = (0, _jwtUtils.decodeToken)(this.idToken);
|
|
8885
|
+
if (decoded === null || decoded === void 0 ? void 0 : decoded.payload) {
|
|
8886
|
+
this.userInfo = decoded.payload;
|
|
8887
|
+
}
|
|
8888
|
+
}
|
|
8889
|
+
if (this.onSuccess) {
|
|
8890
|
+
this.onSuccess(response);
|
|
8891
|
+
}
|
|
8892
|
+
}
|
|
8893
|
+
return;
|
|
8894
|
+
} catch (error) {
|
|
8895
|
+
console.error("[ISA-AUTH] Apple sign-in failed:", error);
|
|
8896
|
+
if (this.onFail) {
|
|
8897
|
+
this.onFail(error);
|
|
8529
8898
|
}
|
|
8899
|
+
return;
|
|
8530
8900
|
}
|
|
8531
|
-
}
|
|
8532
|
-
|
|
8533
|
-
|
|
8534
|
-
|
|
8901
|
+
}
|
|
8902
|
+
const authUrl = this.buildAuthUrl();
|
|
8903
|
+
if (this.usePopup) {
|
|
8904
|
+
const popup = (0, _pkce.openOAuthPopup)(authUrl, "apple_login", 500, 650);
|
|
8905
|
+
if (!popup) {
|
|
8906
|
+
window.location.href = authUrl;
|
|
8907
|
+
return;
|
|
8535
8908
|
}
|
|
8909
|
+
try {
|
|
8910
|
+
const result = await (0, _pkce.waitForOAuthPopupMessage)(popup, { expectedState: this.lastState });
|
|
8911
|
+
if (result.id_token) {
|
|
8912
|
+
this.idToken = result.id_token;
|
|
8913
|
+
const decoded = (0, _jwtUtils.decodeToken)(result.id_token);
|
|
8914
|
+
if (decoded === null || decoded === void 0 ? void 0 : decoded.payload) {
|
|
8915
|
+
this.userInfo = decoded.payload;
|
|
8916
|
+
}
|
|
8917
|
+
}
|
|
8918
|
+
if (result.code && !this.idToken) {
|
|
8919
|
+
this.idToken = result.code;
|
|
8920
|
+
}
|
|
8921
|
+
if (this.onSuccess) this.onSuccess(result);
|
|
8922
|
+
} catch (err) {
|
|
8923
|
+
if (this.onFail) this.onFail(err);
|
|
8924
|
+
}
|
|
8925
|
+
} else {
|
|
8926
|
+
window.location.href = authUrl;
|
|
8536
8927
|
}
|
|
8537
8928
|
}
|
|
8538
8929
|
signOut() {
|
|
8539
8930
|
this.idToken = null;
|
|
8540
8931
|
this.userInfo = null;
|
|
8541
8932
|
}
|
|
8542
|
-
async getAccessToken() {
|
|
8543
|
-
return this.idToken;
|
|
8544
|
-
}
|
|
8545
|
-
async getUserInfo() {
|
|
8546
|
-
return this.userInfo;
|
|
8547
|
-
}
|
|
8548
|
-
constructor(options) {
|
|
8549
|
-
_define_property(this, "clientId", void 0);
|
|
8550
|
-
_define_property(this, "redirectURI", void 0);
|
|
8551
|
-
_define_property(this, "scope", void 0);
|
|
8552
|
-
_define_property(this, "state", void 0);
|
|
8553
|
-
_define_property(this, "nonce", void 0);
|
|
8554
|
-
_define_property(this, "usePopup", void 0);
|
|
8555
|
-
_define_property(this, "onSuccess", void 0);
|
|
8556
|
-
_define_property(this, "onFail", void 0);
|
|
8557
|
-
_define_property(this, "idToken", null);
|
|
8558
|
-
_define_property(this, "userInfo", null);
|
|
8559
|
-
this.clientId = options.clientId;
|
|
8560
|
-
this.redirectURI = options.redirectURI || (typeof window !== "undefined" ? window.location.origin : "");
|
|
8561
|
-
this.scope = options.scope || "name email";
|
|
8562
|
-
this.state = options.state;
|
|
8563
|
-
this.nonce = options.nonce;
|
|
8564
|
-
var _options_usePopup;
|
|
8565
|
-
this.usePopup = (_options_usePopup = options.usePopup) !== null && _options_usePopup !== void 0 ? _options_usePopup : true;
|
|
8566
|
-
this.onSuccess = options.onSuccess;
|
|
8567
|
-
this.onFail = options.onFail;
|
|
8568
|
-
}
|
|
8569
|
-
};
|
|
8570
|
-
var _default = AppleAuthProvider2;
|
|
8571
|
-
}
|
|
8572
|
-
});
|
|
8573
|
-
|
|
8574
|
-
// ../core/dist/providers/pkce.js
|
|
8575
|
-
var require_pkce = __commonJS({
|
|
8576
|
-
"../core/dist/providers/pkce.js"(exports2) {
|
|
8577
|
-
"use strict";
|
|
8578
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
8579
|
-
function _export(target, all) {
|
|
8580
|
-
for (var name in all) Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get });
|
|
8581
|
-
}
|
|
8582
|
-
_export(exports2, { get buildAuthorizeUrl() {
|
|
8583
|
-
return buildAuthorizeUrl2;
|
|
8584
|
-
}, get generateCodeChallenge() {
|
|
8585
|
-
return generateCodeChallenge2;
|
|
8586
|
-
}, get generateCodeVerifier() {
|
|
8587
|
-
return generateCodeVerifier2;
|
|
8588
|
-
}, get parseOAuthCallback() {
|
|
8589
|
-
return parseOAuthCallback2;
|
|
8590
|
-
} });
|
|
8591
|
-
var _jwtUtils = require_jwtUtils();
|
|
8592
|
-
function generateCodeVerifier2(length = 64) {
|
|
8593
|
-
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
8594
|
-
const array = new Uint8Array(length);
|
|
8595
|
-
if (typeof window !== "undefined" && window.crypto) {
|
|
8596
|
-
window.crypto.getRandomValues(array);
|
|
8597
|
-
} else {
|
|
8598
|
-
for (let i = 0; i < length; i++) {
|
|
8599
|
-
array[i] = Math.floor(Math.random() * 256);
|
|
8600
|
-
}
|
|
8601
|
-
}
|
|
8602
|
-
let result = "";
|
|
8603
|
-
for (let i = 0; i < length; i++) {
|
|
8604
|
-
result += charset[array[i] % charset.length];
|
|
8605
|
-
}
|
|
8606
|
-
return result;
|
|
8607
|
-
}
|
|
8608
|
-
async function generateCodeChallenge2(verifier) {
|
|
8609
|
-
if (typeof window !== "undefined" && window.crypto && window.crypto.subtle) {
|
|
8610
|
-
const encoder = new TextEncoder();
|
|
8611
|
-
const data = encoder.encode(verifier);
|
|
8612
|
-
const digest = await window.crypto.subtle.digest("SHA-256", data);
|
|
8613
|
-
const bytes = new Uint8Array(digest);
|
|
8614
|
-
let binary = "";
|
|
8615
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
8616
|
-
binary += String.fromCharCode(bytes[i]);
|
|
8617
|
-
}
|
|
8618
|
-
const base64 = btoa(binary);
|
|
8619
|
-
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
8933
|
+
async getAccessToken() {
|
|
8934
|
+
return this.idToken;
|
|
8620
8935
|
}
|
|
8621
|
-
|
|
8622
|
-
|
|
8623
|
-
function buildAuthorizeUrl2(options) {
|
|
8624
|
-
const { authorizeUrl, clientId, redirectUri, responseType = "code", scope, state, codeChallenge, codeChallengeMethod = "S256", extraParams = {} } = options;
|
|
8625
|
-
const url = new URL(authorizeUrl);
|
|
8626
|
-
url.searchParams.set("client_id", clientId);
|
|
8627
|
-
url.searchParams.set("redirect_uri", redirectUri);
|
|
8628
|
-
url.searchParams.set("response_type", responseType);
|
|
8629
|
-
if (scope) url.searchParams.set("scope", scope);
|
|
8630
|
-
if (state) url.searchParams.set("state", state);
|
|
8631
|
-
if (codeChallenge) {
|
|
8632
|
-
url.searchParams.set("code_challenge", codeChallenge);
|
|
8633
|
-
url.searchParams.set("code_challenge_method", codeChallengeMethod);
|
|
8936
|
+
async getUserInfo() {
|
|
8937
|
+
return this.userInfo;
|
|
8634
8938
|
}
|
|
8635
|
-
|
|
8636
|
-
|
|
8939
|
+
setToken(token) {
|
|
8940
|
+
this.idToken = token;
|
|
8637
8941
|
}
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
let search = "";
|
|
8642
|
-
if (urlOrSearch) {
|
|
8643
|
-
search = urlOrSearch.includes("?") ? urlOrSearch.split("?")[1] : urlOrSearch;
|
|
8644
|
-
} else if (typeof window !== "undefined") {
|
|
8645
|
-
search = window.location.search.slice(1);
|
|
8942
|
+
setUser(user) {
|
|
8943
|
+
this.userInfo = user;
|
|
8944
|
+
if (this.onSuccess) this.onSuccess(user);
|
|
8646
8945
|
}
|
|
8647
|
-
|
|
8648
|
-
|
|
8649
|
-
|
|
8650
|
-
|
|
8651
|
-
|
|
8652
|
-
|
|
8653
|
-
|
|
8946
|
+
constructor(options) {
|
|
8947
|
+
_define_property(this, "clientId", void 0);
|
|
8948
|
+
_define_property(this, "redirectURI", void 0);
|
|
8949
|
+
_define_property(this, "scope", void 0);
|
|
8950
|
+
_define_property(this, "state", void 0);
|
|
8951
|
+
_define_property(this, "lastState", void 0);
|
|
8952
|
+
_define_property(this, "nonce", void 0);
|
|
8953
|
+
_define_property(this, "usePopup", void 0);
|
|
8954
|
+
_define_property(this, "responseMode", void 0);
|
|
8955
|
+
_define_property(this, "onSuccess", void 0);
|
|
8956
|
+
_define_property(this, "onFail", void 0);
|
|
8957
|
+
_define_property(this, "idToken", null);
|
|
8958
|
+
_define_property(this, "userInfo", null);
|
|
8959
|
+
this.clientId = options.clientId;
|
|
8960
|
+
this.redirectURI = options.redirectURI || (typeof window !== "undefined" ? window.location.origin : "");
|
|
8961
|
+
this.scope = options.scope !== void 0 ? options.scope : "name email";
|
|
8962
|
+
this.state = options.state;
|
|
8963
|
+
this.nonce = options.nonce;
|
|
8964
|
+
var _options_usePopup;
|
|
8965
|
+
this.usePopup = (_options_usePopup = options.usePopup) !== null && _options_usePopup !== void 0 ? _options_usePopup : true;
|
|
8966
|
+
this.responseMode = options.responseMode;
|
|
8967
|
+
this.onSuccess = options.onSuccess;
|
|
8968
|
+
this.onFail = options.onFail;
|
|
8969
|
+
}
|
|
8970
|
+
};
|
|
8971
|
+
var _default = AppleAuthProvider2;
|
|
8654
8972
|
}
|
|
8655
8973
|
});
|
|
8656
8974
|
|
|
@@ -8663,7 +8981,7 @@ var require_metaAuth = __commonJS({
|
|
|
8663
8981
|
for (var name in all) Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get });
|
|
8664
8982
|
}
|
|
8665
8983
|
_export(exports2, { get FacebookAuthProvider() {
|
|
8666
|
-
return
|
|
8984
|
+
return MetaAuthProvider2;
|
|
8667
8985
|
}, get MetaAuthProvider() {
|
|
8668
8986
|
return MetaAuthProvider2;
|
|
8669
8987
|
}, get default() {
|
|
@@ -8688,57 +9006,108 @@ var require_metaAuth = __commonJS({
|
|
|
8688
9006
|
}
|
|
8689
9007
|
async init() {
|
|
8690
9008
|
if (typeof window === "undefined") return;
|
|
8691
|
-
|
|
8692
|
-
|
|
8693
|
-
window.FB
|
|
9009
|
+
try {
|
|
9010
|
+
await this.loadFacebookSdk();
|
|
9011
|
+
if (window.FB) {
|
|
9012
|
+
window.FB.init({ appId: this.appId, cookie: true, xfbml: true, version: this.version });
|
|
9013
|
+
}
|
|
9014
|
+
} catch (e) {
|
|
8694
9015
|
}
|
|
8695
9016
|
}
|
|
8696
|
-
|
|
9017
|
+
buildAuthUrl() {
|
|
9018
|
+
const state = (0, _pkce.generateRandomState)();
|
|
9019
|
+
this.lastState = state;
|
|
9020
|
+
return (0, _pkce.buildAuthorizeUrl)({ authorizeUrl: `https://www.facebook.com/${this.version}/dialog/oauth`, clientId: this.appId, redirectUri: this.redirectUri || (typeof window !== "undefined" ? window.location.origin : ""), responseType: "token", scope: this.scope, state });
|
|
9021
|
+
}
|
|
9022
|
+
async signIn() {
|
|
8697
9023
|
if (typeof window === "undefined") return;
|
|
8698
|
-
if (window.FB && this.
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
|
|
8706
|
-
|
|
8707
|
-
|
|
8708
|
-
|
|
8709
|
-
|
|
8710
|
-
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
9024
|
+
if (window.FB && typeof window.FB.login === "function" && !this.redirectUri) {
|
|
9025
|
+
return new Promise((resolve, reject) => {
|
|
9026
|
+
window.FB.login((response) => {
|
|
9027
|
+
if (response.authResponse) {
|
|
9028
|
+
this.accessToken = response.authResponse.accessToken;
|
|
9029
|
+
this.fetchUserInfo().then((user) => {
|
|
9030
|
+
if (this.onSuccess) this.onSuccess(user || response);
|
|
9031
|
+
resolve();
|
|
9032
|
+
}).catch(() => {
|
|
9033
|
+
if (this.onSuccess) this.onSuccess(response);
|
|
9034
|
+
resolve();
|
|
9035
|
+
});
|
|
9036
|
+
} else {
|
|
9037
|
+
const err = new Error("Meta login cancelled or failed");
|
|
9038
|
+
if (this.onFail) this.onFail(err);
|
|
9039
|
+
reject(err);
|
|
9040
|
+
}
|
|
9041
|
+
}, { scope: this.scope });
|
|
9042
|
+
});
|
|
9043
|
+
}
|
|
9044
|
+
const authUrl = this.buildAuthUrl();
|
|
9045
|
+
if (this.isPopup) {
|
|
9046
|
+
const popup = (0, _pkce.openOAuthPopup)(authUrl, "meta_oauth_login", 600, 700);
|
|
9047
|
+
if (!popup) {
|
|
8714
9048
|
window.location.href = authUrl;
|
|
9049
|
+
return;
|
|
8715
9050
|
}
|
|
9051
|
+
try {
|
|
9052
|
+
const result = await (0, _pkce.waitForOAuthPopupMessage)(popup, { expectedState: this.lastState });
|
|
9053
|
+
if (result.access_token || result.token) {
|
|
9054
|
+
this.accessToken = result.access_token || result.token || null;
|
|
9055
|
+
} else if (result.code) {
|
|
9056
|
+
this.accessToken = result.code;
|
|
9057
|
+
}
|
|
9058
|
+
if (this.onSuccess) this.onSuccess(result);
|
|
9059
|
+
} catch (err) {
|
|
9060
|
+
if (this.onFail) this.onFail(err);
|
|
9061
|
+
}
|
|
9062
|
+
} else {
|
|
9063
|
+
window.location.href = authUrl;
|
|
8716
9064
|
}
|
|
8717
9065
|
}
|
|
8718
9066
|
signOut() {
|
|
8719
|
-
|
|
8720
|
-
|
|
8721
|
-
|
|
8722
|
-
|
|
9067
|
+
this.accessToken = null;
|
|
9068
|
+
this.userInfo = null;
|
|
9069
|
+
if (typeof window !== "undefined" && window.FB && typeof window.FB.logout === "function") {
|
|
9070
|
+
try {
|
|
9071
|
+
window.FB.logout(() => {
|
|
9072
|
+
});
|
|
9073
|
+
} catch (e) {
|
|
9074
|
+
}
|
|
9075
|
+
}
|
|
9076
|
+
}
|
|
9077
|
+
async fetchUserInfo() {
|
|
9078
|
+
var _window_FB_getAccessToken, _window_FB;
|
|
9079
|
+
if (typeof window === "undefined") return null;
|
|
9080
|
+
if (window.FB && typeof window.FB.api === "function" && ((_window_FB_getAccessToken = (_window_FB = window.FB).getAccessToken) === null || _window_FB_getAccessToken === void 0 ? void 0 : _window_FB_getAccessToken.call(_window_FB))) {
|
|
9081
|
+
return new Promise((resolve, reject) => {
|
|
9082
|
+
window.FB.api("/me", { fields: "id,name,email,picture" }, (response) => {
|
|
9083
|
+
if (!response || response.error) {
|
|
9084
|
+
reject((response === null || response === void 0 ? void 0 : response.error) || new Error("Failed to fetch FB user"));
|
|
9085
|
+
} else {
|
|
9086
|
+
this.userInfo = response;
|
|
9087
|
+
resolve(response);
|
|
9088
|
+
}
|
|
9089
|
+
});
|
|
8723
9090
|
});
|
|
8724
|
-
} else {
|
|
8725
|
-
this.accessToken = null;
|
|
8726
|
-
this.userInfo = null;
|
|
8727
9091
|
}
|
|
9092
|
+
if (this.accessToken) {
|
|
9093
|
+
const res = await fetch(`https://graph.facebook.com/${this.version}/me?fields=id,name,email,picture`, { headers: { Authorization: `Bearer ${this.accessToken}` } });
|
|
9094
|
+
if (res.ok) {
|
|
9095
|
+
this.userInfo = await res.json();
|
|
9096
|
+
return this.userInfo;
|
|
9097
|
+
}
|
|
9098
|
+
}
|
|
9099
|
+
return null;
|
|
8728
9100
|
}
|
|
8729
9101
|
async getAccessToken() {
|
|
8730
9102
|
return this.accessToken;
|
|
8731
9103
|
}
|
|
8732
9104
|
async getUserInfo() {
|
|
8733
|
-
if (
|
|
8734
|
-
|
|
9105
|
+
if (this.userInfo) return this.userInfo;
|
|
9106
|
+
try {
|
|
9107
|
+
return await this.fetchUserInfo();
|
|
9108
|
+
} catch (e) {
|
|
9109
|
+
return null;
|
|
8735
9110
|
}
|
|
8736
|
-
return new Promise((resolve) => {
|
|
8737
|
-
window.FB.api("/me", { fields: "id,name,email,picture" }, (res) => {
|
|
8738
|
-
this.userInfo = res;
|
|
8739
|
-
resolve(res);
|
|
8740
|
-
});
|
|
8741
|
-
});
|
|
8742
9111
|
}
|
|
8743
9112
|
setToken(token) {
|
|
8744
9113
|
this.accessToken = token;
|
|
@@ -8753,12 +9122,13 @@ var require_metaAuth = __commonJS({
|
|
|
8753
9122
|
_define_property(this, "redirectUri", void 0);
|
|
8754
9123
|
_define_property(this, "scope", void 0);
|
|
8755
9124
|
_define_property(this, "isPopup", void 0);
|
|
9125
|
+
_define_property(this, "lastState", void 0);
|
|
8756
9126
|
_define_property(this, "onSuccess", void 0);
|
|
8757
9127
|
_define_property(this, "onFail", void 0);
|
|
8758
9128
|
_define_property(this, "accessToken", null);
|
|
8759
9129
|
_define_property(this, "userInfo", null);
|
|
8760
9130
|
this.appId = options.appId;
|
|
8761
|
-
this.version = options.version || "
|
|
9131
|
+
this.version = options.version || "v21.0";
|
|
8762
9132
|
this.redirectUri = options.redirectUri;
|
|
8763
9133
|
this.scope = options.scope || "public_profile,email";
|
|
8764
9134
|
var _options_isPopup;
|
|
@@ -8767,7 +9137,6 @@ var require_metaAuth = __commonJS({
|
|
|
8767
9137
|
this.onFail = options.onFail;
|
|
8768
9138
|
}
|
|
8769
9139
|
};
|
|
8770
|
-
var FacebookAuthProvider2 = MetaAuthProvider2;
|
|
8771
9140
|
var _default = MetaAuthProvider2;
|
|
8772
9141
|
}
|
|
8773
9142
|
});
|
|
@@ -8786,6 +9155,7 @@ var require_kakaoAuth = __commonJS({
|
|
|
8786
9155
|
return _default;
|
|
8787
9156
|
} });
|
|
8788
9157
|
var _isautil = require_dist();
|
|
9158
|
+
var _pkce = require_pkce();
|
|
8789
9159
|
function _define_property(obj, key, value) {
|
|
8790
9160
|
if (key in obj) {
|
|
8791
9161
|
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
@@ -8795,6 +9165,11 @@ var require_kakaoAuth = __commonJS({
|
|
|
8795
9165
|
return obj;
|
|
8796
9166
|
}
|
|
8797
9167
|
var KakaoAuthProvider2 = class {
|
|
9168
|
+
buildAuthUrl() {
|
|
9169
|
+
const state = this.state || (0, _pkce.generateRandomState)();
|
|
9170
|
+
this.lastState = state;
|
|
9171
|
+
return (0, _pkce.buildAuthorizeUrl)({ authorizeUrl: "https://kauth.kakao.com/oauth/authorize", clientId: this.restApiKey || this.javascriptKey, redirectUri: this.redirectUri || (typeof window !== "undefined" ? window.location.origin : ""), responseType: "code", scope: this.scope, state });
|
|
9172
|
+
}
|
|
8798
9173
|
async loadKakaoSdk() {
|
|
8799
9174
|
if (typeof window !== "undefined" && window.Kakao) {
|
|
8800
9175
|
return;
|
|
@@ -8803,54 +9178,158 @@ var require_kakaoAuth = __commonJS({
|
|
|
8803
9178
|
}
|
|
8804
9179
|
async init() {
|
|
8805
9180
|
if (typeof window === "undefined") return;
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
window.Kakao.
|
|
9181
|
+
try {
|
|
9182
|
+
await this.loadKakaoSdk();
|
|
9183
|
+
if (window.Kakao && !window.Kakao.isInitialized()) {
|
|
9184
|
+
window.Kakao.init(this.javascriptKey);
|
|
9185
|
+
}
|
|
9186
|
+
} catch (e) {
|
|
8809
9187
|
}
|
|
8810
9188
|
}
|
|
8811
|
-
signIn() {
|
|
8812
|
-
|
|
8813
|
-
|
|
9189
|
+
async signIn() {
|
|
9190
|
+
var _window_Kakao_Auth;
|
|
9191
|
+
if (typeof window === "undefined") return;
|
|
9192
|
+
if (this.isPopup) {
|
|
9193
|
+
var _window_Kakao_Auth1;
|
|
9194
|
+
if (window.Kakao && typeof ((_window_Kakao_Auth1 = window.Kakao.Auth) === null || _window_Kakao_Auth1 === void 0 ? void 0 : _window_Kakao_Auth1.login) === "function" && !this.redirectUri) {
|
|
9195
|
+
return new Promise((resolve, reject) => {
|
|
9196
|
+
window.Kakao.Auth.login({ scope: this.scope, success: async (authObj) => {
|
|
9197
|
+
this.accessToken = authObj.access_token;
|
|
9198
|
+
try {
|
|
9199
|
+
await this.fetchUserInfo();
|
|
9200
|
+
} catch (e) {
|
|
9201
|
+
}
|
|
9202
|
+
if (this.onSuccess) this.onSuccess(authObj);
|
|
9203
|
+
resolve();
|
|
9204
|
+
}, fail: (err) => {
|
|
9205
|
+
if (this.onFail) this.onFail(err);
|
|
9206
|
+
reject(err);
|
|
9207
|
+
} });
|
|
9208
|
+
});
|
|
9209
|
+
}
|
|
9210
|
+
const authUrl = this.buildAuthUrl();
|
|
9211
|
+
const popup = (0, _pkce.openOAuthPopup)(authUrl, "kakao_login", 480, 600);
|
|
9212
|
+
if (!popup) {
|
|
9213
|
+
window.location.href = authUrl;
|
|
9214
|
+
return;
|
|
9215
|
+
}
|
|
9216
|
+
try {
|
|
9217
|
+
const result = await (0, _pkce.waitForOAuthPopupMessage)(popup, { expectedState: this.lastState });
|
|
9218
|
+
if (result.access_token || result.token) {
|
|
9219
|
+
this.accessToken = result.access_token || result.token || null;
|
|
9220
|
+
} else if (result.code) {
|
|
9221
|
+
this.accessToken = result.code;
|
|
9222
|
+
}
|
|
9223
|
+
if (this.onSuccess) this.onSuccess(result);
|
|
9224
|
+
} catch (err) {
|
|
9225
|
+
if (this.onFail) this.onFail(err);
|
|
9226
|
+
}
|
|
8814
9227
|
return;
|
|
8815
9228
|
}
|
|
8816
|
-
if (this.redirectUri) {
|
|
9229
|
+
if (window.Kakao && typeof ((_window_Kakao_Auth = window.Kakao.Auth) === null || _window_Kakao_Auth === void 0 ? void 0 : _window_Kakao_Auth.authorize) === "function" && this.redirectUri) {
|
|
8817
9230
|
window.Kakao.Auth.authorize({ redirectUri: this.redirectUri, scope: this.scope });
|
|
8818
|
-
|
|
8819
|
-
window.Kakao.Auth.login({ scope: this.scope, success: (authObj) => {
|
|
8820
|
-
if (this.onSuccess) this.onSuccess(authObj);
|
|
8821
|
-
}, fail: (err) => {
|
|
8822
|
-
if (this.onFail) this.onFail(err);
|
|
8823
|
-
} });
|
|
9231
|
+
return;
|
|
8824
9232
|
}
|
|
9233
|
+
window.location.href = this.buildAuthUrl();
|
|
8825
9234
|
}
|
|
8826
9235
|
signOut() {
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
9236
|
+
var _window_Kakao_Auth_getAccessToken, _window_Kakao_Auth;
|
|
9237
|
+
this.accessToken = null;
|
|
9238
|
+
this.userInfo = null;
|
|
9239
|
+
if (typeof window !== "undefined" && window.Kakao && ((_window_Kakao_Auth = window.Kakao.Auth) === null || _window_Kakao_Auth === void 0 ? void 0 : (_window_Kakao_Auth_getAccessToken = _window_Kakao_Auth.getAccessToken) === null || _window_Kakao_Auth_getAccessToken === void 0 ? void 0 : _window_Kakao_Auth_getAccessToken.call(_window_Kakao_Auth))) {
|
|
9240
|
+
try {
|
|
9241
|
+
Promise.resolve(window.Kakao.Auth.logout(() => {
|
|
9242
|
+
})).catch(() => {
|
|
9243
|
+
});
|
|
9244
|
+
} catch (e) {
|
|
9245
|
+
}
|
|
9246
|
+
}
|
|
9247
|
+
}
|
|
9248
|
+
async fetchUserInfo() {
|
|
9249
|
+
var _window_Kakao_API, _window_Kakao_Auth_getAccessToken, _window_Kakao_Auth;
|
|
9250
|
+
if (typeof window === "undefined") return null;
|
|
9251
|
+
if (window.Kakao && typeof ((_window_Kakao_API = window.Kakao.API) === null || _window_Kakao_API === void 0 ? void 0 : _window_Kakao_API.request) === "function" && ((_window_Kakao_Auth = window.Kakao.Auth) === null || _window_Kakao_Auth === void 0 ? void 0 : (_window_Kakao_Auth_getAccessToken = _window_Kakao_Auth.getAccessToken) === null || _window_Kakao_Auth_getAccessToken === void 0 ? void 0 : _window_Kakao_Auth_getAccessToken.call(_window_Kakao_Auth))) {
|
|
9252
|
+
return new Promise((resolve, reject) => {
|
|
9253
|
+
let settled = false;
|
|
9254
|
+
const maybePromise = window.Kakao.API.request({ url: "/v2/user/me", success: (response) => {
|
|
9255
|
+
if (!settled) {
|
|
9256
|
+
settled = true;
|
|
9257
|
+
this.userInfo = response;
|
|
9258
|
+
resolve(response);
|
|
9259
|
+
}
|
|
9260
|
+
}, fail: (error) => {
|
|
9261
|
+
if (!settled) {
|
|
9262
|
+
settled = true;
|
|
9263
|
+
reject(error);
|
|
9264
|
+
}
|
|
9265
|
+
} });
|
|
9266
|
+
if (maybePromise && typeof maybePromise.then === "function") {
|
|
9267
|
+
maybePromise.then((response) => {
|
|
9268
|
+
if (!settled) {
|
|
9269
|
+
settled = true;
|
|
9270
|
+
this.userInfo = response;
|
|
9271
|
+
resolve(response);
|
|
9272
|
+
}
|
|
9273
|
+
}).catch((error) => {
|
|
9274
|
+
if (!settled) {
|
|
9275
|
+
settled = true;
|
|
9276
|
+
reject(error);
|
|
9277
|
+
}
|
|
9278
|
+
});
|
|
9279
|
+
}
|
|
8830
9280
|
});
|
|
8831
9281
|
}
|
|
9282
|
+
if (this.accessToken) {
|
|
9283
|
+
const res = await fetch("https://kapi.kakao.com/v2/user/me", { headers: { Authorization: `Bearer ${this.accessToken}`, "Content-Type": "application/x-www-form-urlencoded;charset=utf-8" } });
|
|
9284
|
+
if (res.ok) {
|
|
9285
|
+
this.userInfo = await res.json();
|
|
9286
|
+
return this.userInfo;
|
|
9287
|
+
}
|
|
9288
|
+
}
|
|
9289
|
+
return null;
|
|
8832
9290
|
}
|
|
8833
9291
|
async getAccessToken() {
|
|
8834
|
-
|
|
9292
|
+
var _window_Kakao_Auth, _window_Kakao;
|
|
9293
|
+
if (this.accessToken) return this.accessToken;
|
|
9294
|
+
if (typeof window !== "undefined" && ((_window_Kakao = window.Kakao) === null || _window_Kakao === void 0 ? void 0 : (_window_Kakao_Auth = _window_Kakao.Auth) === null || _window_Kakao_Auth === void 0 ? void 0 : _window_Kakao_Auth.getAccessToken)) {
|
|
8835
9295
|
return window.Kakao.Auth.getAccessToken() || null;
|
|
8836
9296
|
}
|
|
8837
9297
|
return null;
|
|
8838
9298
|
}
|
|
8839
9299
|
async getUserInfo() {
|
|
8840
|
-
if (
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
})
|
|
9300
|
+
if (this.userInfo) return this.userInfo;
|
|
9301
|
+
try {
|
|
9302
|
+
return await this.fetchUserInfo();
|
|
9303
|
+
} catch (e) {
|
|
9304
|
+
return null;
|
|
9305
|
+
}
|
|
9306
|
+
}
|
|
9307
|
+
setToken(token) {
|
|
9308
|
+
this.accessToken = token;
|
|
9309
|
+
}
|
|
9310
|
+
setUser(user) {
|
|
9311
|
+
this.userInfo = user;
|
|
9312
|
+
if (this.onSuccess) this.onSuccess(user);
|
|
8844
9313
|
}
|
|
8845
9314
|
constructor(options) {
|
|
8846
9315
|
_define_property(this, "javascriptKey", void 0);
|
|
9316
|
+
_define_property(this, "restApiKey", void 0);
|
|
8847
9317
|
_define_property(this, "redirectUri", void 0);
|
|
8848
9318
|
_define_property(this, "scope", void 0);
|
|
9319
|
+
_define_property(this, "isPopup", void 0);
|
|
9320
|
+
_define_property(this, "state", void 0);
|
|
9321
|
+
_define_property(this, "lastState", void 0);
|
|
8849
9322
|
_define_property(this, "onSuccess", void 0);
|
|
8850
9323
|
_define_property(this, "onFail", void 0);
|
|
9324
|
+
_define_property(this, "accessToken", null);
|
|
9325
|
+
_define_property(this, "userInfo", null);
|
|
8851
9326
|
this.javascriptKey = options.javascriptKey;
|
|
9327
|
+
this.restApiKey = options.restApiKey;
|
|
8852
9328
|
this.redirectUri = options.redirectUri;
|
|
8853
9329
|
this.scope = options.scope;
|
|
9330
|
+
var _options_isPopup;
|
|
9331
|
+
this.isPopup = (_options_isPopup = options.isPopup) !== null && _options_isPopup !== void 0 ? _options_isPopup : true;
|
|
9332
|
+
this.state = options.state;
|
|
8854
9333
|
this.onSuccess = options.onSuccess;
|
|
8855
9334
|
this.onFail = options.onFail;
|
|
8856
9335
|
}
|
|
@@ -8873,6 +9352,7 @@ var require_naverAuth = __commonJS({
|
|
|
8873
9352
|
return _default;
|
|
8874
9353
|
} });
|
|
8875
9354
|
var _isautil = require_dist();
|
|
9355
|
+
var _pkce = require_pkce();
|
|
8876
9356
|
function _define_property(obj, key, value) {
|
|
8877
9357
|
if (key in obj) {
|
|
8878
9358
|
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
@@ -8882,82 +9362,137 @@ var require_naverAuth = __commonJS({
|
|
|
8882
9362
|
return obj;
|
|
8883
9363
|
}
|
|
8884
9364
|
var NaverAuthProvider2 = class {
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
}
|
|
9365
|
+
buildAuthUrl() {
|
|
9366
|
+
const state = this.state || (0, _pkce.generateRandomState)();
|
|
9367
|
+
this.lastState = state;
|
|
9368
|
+
return (0, _pkce.buildAuthorizeUrl)({ authorizeUrl: "https://nid.naver.com/oauth2.0/authorize", clientId: this.clientId, redirectUri: this.callbackUrl, responseType: this.responseType, state });
|
|
9369
|
+
}
|
|
9370
|
+
async loadLegacySdk() {
|
|
9371
|
+
var _window_naver;
|
|
9372
|
+
if (typeof window === "undefined" || ((_window_naver = window.naver) === null || _window_naver === void 0 ? void 0 : _window_naver.LoginWithNaverId)) return;
|
|
8889
9373
|
await (0, _isautil.loadCDN)("naver-login-sdk", "https://static.nid.naver.com/js/naveridlogin_js_sdk_2.0.2.js", { async: true, defer: true });
|
|
8890
9374
|
}
|
|
8891
9375
|
async init() {
|
|
8892
9376
|
if (typeof window === "undefined") return;
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
if (
|
|
8897
|
-
|
|
8898
|
-
btnEl
|
|
8899
|
-
btnEl
|
|
8900
|
-
|
|
8901
|
-
|
|
8902
|
-
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
|
|
9377
|
+
if (this.useLegacySdk) {
|
|
9378
|
+
var _window_naver;
|
|
9379
|
+
await this.loadLegacySdk();
|
|
9380
|
+
if ((_window_naver = window.naver) === null || _window_naver === void 0 ? void 0 : _window_naver.LoginWithNaverId) {
|
|
9381
|
+
const btnId = this.loginButtonId || "naverIdLogin";
|
|
9382
|
+
let btnEl = document.getElementById(btnId);
|
|
9383
|
+
if (!btnEl && typeof document !== "undefined") {
|
|
9384
|
+
btnEl = document.createElement("div");
|
|
9385
|
+
btnEl.id = btnId;
|
|
9386
|
+
btnEl.style.display = "none";
|
|
9387
|
+
document.body.appendChild(btnEl);
|
|
9388
|
+
}
|
|
9389
|
+
this.naverLoginInstance = new window.naver.LoginWithNaverId({ clientId: this.clientId, callbackUrl: this.callbackUrl, isPopup: this.isPopup, loginButton: { color: "green", type: 3, height: 48 } });
|
|
9390
|
+
try {
|
|
9391
|
+
this.naverLoginInstance.init();
|
|
9392
|
+
} catch (err) {
|
|
9393
|
+
}
|
|
8906
9394
|
}
|
|
8907
9395
|
}
|
|
8908
9396
|
}
|
|
8909
|
-
signIn() {
|
|
9397
|
+
async signIn() {
|
|
8910
9398
|
if (typeof window === "undefined") return;
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
link.
|
|
8915
|
-
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
|
|
9399
|
+
if (this.useLegacySdk && this.naverLoginInstance) {
|
|
9400
|
+
const btnId = this.loginButtonId || "naverIdLogin";
|
|
9401
|
+
const buttonElement = document.getElementById(btnId);
|
|
9402
|
+
const link = buttonElement === null || buttonElement === void 0 ? void 0 : buttonElement.querySelector("a");
|
|
9403
|
+
if (link) {
|
|
9404
|
+
link.click();
|
|
9405
|
+
return;
|
|
9406
|
+
}
|
|
9407
|
+
}
|
|
9408
|
+
const authUrl = this.buildAuthUrl();
|
|
9409
|
+
if (this.isPopup) {
|
|
9410
|
+
const popup = (0, _pkce.openOAuthPopup)(authUrl, "naver_oauth_login", 500, 650);
|
|
9411
|
+
if (!popup) {
|
|
8920
9412
|
window.location.href = authUrl;
|
|
9413
|
+
return;
|
|
9414
|
+
}
|
|
9415
|
+
try {
|
|
9416
|
+
const result = await (0, _pkce.waitForOAuthPopupMessage)(popup, { expectedState: this.lastState });
|
|
9417
|
+
if (result.access_token || result.token) {
|
|
9418
|
+
this.accessToken = result.access_token || result.token || null;
|
|
9419
|
+
} else if (result.code) {
|
|
9420
|
+
this.accessToken = result.code;
|
|
9421
|
+
}
|
|
9422
|
+
if (this.onSuccess) this.onSuccess(result);
|
|
9423
|
+
} catch (err) {
|
|
9424
|
+
if (this.onFail) this.onFail(err);
|
|
8921
9425
|
}
|
|
9426
|
+
} else {
|
|
9427
|
+
window.location.href = authUrl;
|
|
8922
9428
|
}
|
|
8923
9429
|
}
|
|
8924
9430
|
signOut() {
|
|
8925
|
-
|
|
8926
|
-
|
|
9431
|
+
this.accessToken = null;
|
|
9432
|
+
this.userInfo = null;
|
|
9433
|
+
if (this.naverLoginInstance && typeof this.naverLoginInstance.logout === "function") {
|
|
9434
|
+
try {
|
|
9435
|
+
this.naverLoginInstance.logout();
|
|
9436
|
+
} catch (e) {
|
|
9437
|
+
}
|
|
8927
9438
|
}
|
|
8928
9439
|
}
|
|
8929
9440
|
async getAccessToken() {
|
|
9441
|
+
if (this.accessToken) return this.accessToken;
|
|
8930
9442
|
if (this.naverLoginInstance && this.naverLoginInstance.accessToken) {
|
|
8931
9443
|
return this.naverLoginInstance.accessToken.accessToken || null;
|
|
8932
9444
|
}
|
|
8933
9445
|
return null;
|
|
8934
9446
|
}
|
|
8935
9447
|
async getUserInfo() {
|
|
8936
|
-
if (
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
|
|
8942
|
-
|
|
8943
|
-
|
|
9448
|
+
if (this.userInfo) return this.userInfo;
|
|
9449
|
+
if (this.naverLoginInstance && typeof this.naverLoginInstance.getLoginStatus === "function") {
|
|
9450
|
+
return new Promise((resolve) => {
|
|
9451
|
+
this.naverLoginInstance.getLoginStatus((status) => {
|
|
9452
|
+
if (status) {
|
|
9453
|
+
resolve(this.naverLoginInstance.user);
|
|
9454
|
+
} else {
|
|
9455
|
+
resolve(null);
|
|
9456
|
+
}
|
|
9457
|
+
});
|
|
8944
9458
|
});
|
|
8945
|
-
}
|
|
9459
|
+
}
|
|
9460
|
+
return null;
|
|
9461
|
+
}
|
|
9462
|
+
setToken(token) {
|
|
9463
|
+
this.accessToken = token;
|
|
9464
|
+
}
|
|
9465
|
+
setUser(user) {
|
|
9466
|
+
this.userInfo = user;
|
|
9467
|
+
if (this.onSuccess) this.onSuccess(user);
|
|
8946
9468
|
}
|
|
8947
9469
|
constructor(options) {
|
|
8948
9470
|
_define_property(this, "clientId", void 0);
|
|
8949
9471
|
_define_property(this, "callbackUrl", void 0);
|
|
9472
|
+
_define_property(this, "responseType", void 0);
|
|
8950
9473
|
_define_property(this, "isPopup", void 0);
|
|
9474
|
+
_define_property(this, "state", void 0);
|
|
9475
|
+
_define_property(this, "lastState", void 0);
|
|
9476
|
+
_define_property(this, "useLegacySdk", void 0);
|
|
8951
9477
|
_define_property(this, "loginButtonId", void 0);
|
|
8952
9478
|
_define_property(this, "callbackHandle", void 0);
|
|
8953
|
-
_define_property(this, "
|
|
9479
|
+
_define_property(this, "onSuccess", void 0);
|
|
9480
|
+
_define_property(this, "onFail", void 0);
|
|
9481
|
+
_define_property(this, "naverLoginInstance", null);
|
|
9482
|
+
_define_property(this, "accessToken", null);
|
|
9483
|
+
_define_property(this, "userInfo", null);
|
|
8954
9484
|
this.clientId = options.clientId;
|
|
8955
9485
|
this.callbackUrl = options.callbackUrl;
|
|
9486
|
+
this.responseType = options.responseType || "code";
|
|
8956
9487
|
var _options_isPopup;
|
|
8957
9488
|
this.isPopup = (_options_isPopup = options.isPopup) !== null && _options_isPopup !== void 0 ? _options_isPopup : true;
|
|
8958
|
-
|
|
8959
|
-
|
|
9489
|
+
this.state = options.state;
|
|
9490
|
+
var _options_useLegacySdk;
|
|
9491
|
+
this.useLegacySdk = (_options_useLegacySdk = options.useLegacySdk) !== null && _options_useLegacySdk !== void 0 ? _options_useLegacySdk : false;
|
|
9492
|
+
this.loginButtonId = options.loginButtonId;
|
|
8960
9493
|
this.callbackHandle = options.callbackHandle;
|
|
9494
|
+
this.onSuccess = options.onSuccess;
|
|
9495
|
+
this.onFail = options.onFail;
|
|
8961
9496
|
}
|
|
8962
9497
|
};
|
|
8963
9498
|
var _default = NaverAuthProvider2;
|
|
@@ -8990,8 +9525,9 @@ var require_lineAuth = __commonJS({
|
|
|
8990
9525
|
async init() {
|
|
8991
9526
|
}
|
|
8992
9527
|
buildLoginUrl() {
|
|
8993
|
-
const state = this.state ||
|
|
8994
|
-
|
|
9528
|
+
const state = this.state || (0, _pkce.generateRandomState)();
|
|
9529
|
+
this.lastState = state;
|
|
9530
|
+
const nonce = this.nonce || (0, _pkce.generateRandomState)();
|
|
8995
9531
|
const extraParams = { nonce };
|
|
8996
9532
|
if (this.botPrompt) extraParams.bot_prompt = this.botPrompt;
|
|
8997
9533
|
return (0, _pkce.buildAuthorizeUrl)({ authorizeUrl: "https://access.line.me/oauth2/v2.1/authorize", clientId: this.clientId, redirectUri: this.callbackUrl, responseType: "code", scope: this.scope, state, extraParams });
|
|
@@ -9001,19 +9537,27 @@ var require_lineAuth = __commonJS({
|
|
|
9001
9537
|
try {
|
|
9002
9538
|
const authUrl = this.buildLoginUrl();
|
|
9003
9539
|
if (this.isPopup) {
|
|
9004
|
-
const
|
|
9005
|
-
const height = 650;
|
|
9006
|
-
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
9007
|
-
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
9008
|
-
const popup = window.open(authUrl, "line_oauth_login", `width=${width},height=${height},left=${left},top=${top},scrollbars=yes`);
|
|
9540
|
+
const popup = (0, _pkce.openOAuthPopup)(authUrl, "line_oauth_login", 500, 650);
|
|
9009
9541
|
if (!popup) {
|
|
9010
9542
|
window.location.href = authUrl;
|
|
9543
|
+
return;
|
|
9544
|
+
}
|
|
9545
|
+
try {
|
|
9546
|
+
const result = await (0, _pkce.waitForOAuthPopupMessage)(popup, { expectedState: this.lastState });
|
|
9547
|
+
if (result.access_token || result.token) {
|
|
9548
|
+
this.accessToken = result.access_token || result.token || null;
|
|
9549
|
+
} else if (result.code) {
|
|
9550
|
+
this.accessToken = result.code;
|
|
9551
|
+
}
|
|
9552
|
+
if (this.onSuccess) this.onSuccess(result);
|
|
9553
|
+
} catch (err) {
|
|
9554
|
+
if (this.onFail) this.onFail(err);
|
|
9011
9555
|
}
|
|
9012
9556
|
} else {
|
|
9013
9557
|
window.location.href = authUrl;
|
|
9014
9558
|
}
|
|
9015
9559
|
} catch (err) {
|
|
9016
|
-
console.error("[ISA-AUTH]
|
|
9560
|
+
console.error("[ISA-AUTH] Line sign-in failed:", err);
|
|
9017
9561
|
if (this.onFail) this.onFail(err);
|
|
9018
9562
|
}
|
|
9019
9563
|
}
|
|
@@ -9039,6 +9583,7 @@ var require_lineAuth = __commonJS({
|
|
|
9039
9583
|
_define_property(this, "callbackUrl", void 0);
|
|
9040
9584
|
_define_property(this, "scope", void 0);
|
|
9041
9585
|
_define_property(this, "state", void 0);
|
|
9586
|
+
_define_property(this, "lastState", void 0);
|
|
9042
9587
|
_define_property(this, "nonce", void 0);
|
|
9043
9588
|
_define_property(this, "isPopup", void 0);
|
|
9044
9589
|
_define_property(this, "botPrompt", void 0);
|
|
@@ -9179,7 +9724,8 @@ var require_githubAuth = __commonJS({
|
|
|
9179
9724
|
}
|
|
9180
9725
|
}
|
|
9181
9726
|
async buildLoginUrl() {
|
|
9182
|
-
const state = this.state ||
|
|
9727
|
+
const state = this.state || (0, _pkce.generateRandomState)();
|
|
9728
|
+
this.lastState = state;
|
|
9183
9729
|
let codeChallenge;
|
|
9184
9730
|
if (this.usePkce && this.codeVerifier) {
|
|
9185
9731
|
codeChallenge = await (0, _pkce.generateCodeChallenge)(this.codeVerifier);
|
|
@@ -9191,13 +9737,21 @@ var require_githubAuth = __commonJS({
|
|
|
9191
9737
|
try {
|
|
9192
9738
|
const authUrl = await this.buildLoginUrl();
|
|
9193
9739
|
if (this.isPopup) {
|
|
9194
|
-
const
|
|
9195
|
-
const height = 700;
|
|
9196
|
-
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
9197
|
-
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
9198
|
-
const popup = window.open(authUrl, "github_oauth_login", `width=${width},height=${height},left=${left},top=${top},scrollbars=yes`);
|
|
9740
|
+
const popup = (0, _pkce.openOAuthPopup)(authUrl, "github_oauth_login", 600, 700);
|
|
9199
9741
|
if (!popup) {
|
|
9200
9742
|
window.location.href = authUrl;
|
|
9743
|
+
return;
|
|
9744
|
+
}
|
|
9745
|
+
try {
|
|
9746
|
+
const result = await (0, _pkce.waitForOAuthPopupMessage)(popup, { expectedState: this.lastState });
|
|
9747
|
+
if (result.access_token || result.token) {
|
|
9748
|
+
this.accessToken = result.access_token || result.token || null;
|
|
9749
|
+
} else if (result.code) {
|
|
9750
|
+
this.accessToken = result.code;
|
|
9751
|
+
}
|
|
9752
|
+
if (this.onSuccess) this.onSuccess(result);
|
|
9753
|
+
} catch (err) {
|
|
9754
|
+
if (this.onFail) this.onFail(err);
|
|
9201
9755
|
}
|
|
9202
9756
|
} else {
|
|
9203
9757
|
window.location.href = authUrl;
|
|
@@ -9233,6 +9787,7 @@ var require_githubAuth = __commonJS({
|
|
|
9233
9787
|
_define_property(this, "scope", void 0);
|
|
9234
9788
|
_define_property(this, "isPopup", void 0);
|
|
9235
9789
|
_define_property(this, "state", void 0);
|
|
9790
|
+
_define_property(this, "lastState", void 0);
|
|
9236
9791
|
_define_property(this, "usePkce", void 0);
|
|
9237
9792
|
_define_property(this, "onSuccess", void 0);
|
|
9238
9793
|
_define_property(this, "onFail", void 0);
|
|
@@ -9287,7 +9842,8 @@ var require_discordAuth = __commonJS({
|
|
|
9287
9842
|
}
|
|
9288
9843
|
}
|
|
9289
9844
|
async buildLoginUrl() {
|
|
9290
|
-
const state = this.state ||
|
|
9845
|
+
const state = this.state || (0, _pkce.generateRandomState)();
|
|
9846
|
+
this.lastState = state;
|
|
9291
9847
|
let codeChallenge;
|
|
9292
9848
|
if (this.usePkce && this.codeVerifier) {
|
|
9293
9849
|
codeChallenge = await (0, _pkce.generateCodeChallenge)(this.codeVerifier);
|
|
@@ -9301,13 +9857,21 @@ var require_discordAuth = __commonJS({
|
|
|
9301
9857
|
try {
|
|
9302
9858
|
const authUrl = await this.buildLoginUrl();
|
|
9303
9859
|
if (this.isPopup) {
|
|
9304
|
-
const
|
|
9305
|
-
const height = 750;
|
|
9306
|
-
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
9307
|
-
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
9308
|
-
const popup = window.open(authUrl, "discord_oauth_login", `width=${width},height=${height},left=${left},top=${top},scrollbars=yes`);
|
|
9860
|
+
const popup = (0, _pkce.openOAuthPopup)(authUrl, "discord_oauth_login", 500, 750);
|
|
9309
9861
|
if (!popup) {
|
|
9310
9862
|
window.location.href = authUrl;
|
|
9863
|
+
return;
|
|
9864
|
+
}
|
|
9865
|
+
try {
|
|
9866
|
+
const result = await (0, _pkce.waitForOAuthPopupMessage)(popup, { expectedState: this.lastState });
|
|
9867
|
+
if (result.access_token || result.token) {
|
|
9868
|
+
this.accessToken = result.access_token || result.token || null;
|
|
9869
|
+
} else if (result.code) {
|
|
9870
|
+
this.accessToken = result.code;
|
|
9871
|
+
}
|
|
9872
|
+
if (this.onSuccess) this.onSuccess(result);
|
|
9873
|
+
} catch (err) {
|
|
9874
|
+
if (this.onFail) this.onFail(err);
|
|
9311
9875
|
}
|
|
9312
9876
|
} else {
|
|
9313
9877
|
window.location.href = authUrl;
|
|
@@ -9343,6 +9907,7 @@ var require_discordAuth = __commonJS({
|
|
|
9343
9907
|
_define_property(this, "scope", void 0);
|
|
9344
9908
|
_define_property(this, "isPopup", void 0);
|
|
9345
9909
|
_define_property(this, "state", void 0);
|
|
9910
|
+
_define_property(this, "lastState", void 0);
|
|
9346
9911
|
_define_property(this, "usePkce", void 0);
|
|
9347
9912
|
_define_property(this, "prompt", void 0);
|
|
9348
9913
|
_define_property(this, "onSuccess", void 0);
|
|
@@ -9416,6 +9981,7 @@ var require_web3Auth = __commonJS({
|
|
|
9416
9981
|
}, get formatSiweMessage() {
|
|
9417
9982
|
return formatSiweMessage;
|
|
9418
9983
|
} });
|
|
9984
|
+
var _pkce = require_pkce();
|
|
9419
9985
|
function _define_property(obj, key, value) {
|
|
9420
9986
|
if (key in obj) {
|
|
9421
9987
|
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
@@ -9466,7 +10032,7 @@ Expiration Time: ${params.expirationTime}`;
|
|
|
9466
10032
|
const accounts = await window.ethereum.request({ method: "eth_requestAccounts" });
|
|
9467
10033
|
const address = accounts[0];
|
|
9468
10034
|
this.connectedAddress = address;
|
|
9469
|
-
const nonce = this.nonceGenerator ? await this.nonceGenerator() :
|
|
10035
|
+
const nonce = this.nonceGenerator ? await this.nonceGenerator() : (0, _pkce.generateRandomState)(16);
|
|
9470
10036
|
const message = formatSiweMessage({ domain: this.domain, address, statement: this.statement, uri: window.location.origin, chainId: this.chainId, nonce });
|
|
9471
10037
|
const signature = await window.ethereum.request({ method: "personal_sign", params: [message, address] });
|
|
9472
10038
|
this.lastSignature = signature;
|
|
@@ -9487,6 +10053,7 @@ Expiration Time: ${params.expirationTime}`;
|
|
|
9487
10053
|
return this.lastSignature;
|
|
9488
10054
|
}
|
|
9489
10055
|
async getUserInfo() {
|
|
10056
|
+
if (!this.connectedAddress) return null;
|
|
9490
10057
|
return { address: this.connectedAddress, chainId: this.chainId };
|
|
9491
10058
|
}
|
|
9492
10059
|
constructor(options = {}) {
|
|
@@ -9602,7 +10169,7 @@ var require_worldAuth = __commonJS({
|
|
|
9602
10169
|
if (typeof window === "undefined") {
|
|
9603
10170
|
throw new Error("World ID authentication requires a browser environment.");
|
|
9604
10171
|
}
|
|
9605
|
-
|
|
10172
|
+
throw new Error("[ISA-AUTH] World ID IDKit widget (window.IDKit) is not loaded. Load @worldcoin/idkit or enable mockProof: true for local testing.");
|
|
9606
10173
|
}
|
|
9607
10174
|
signOut() {
|
|
9608
10175
|
this.lastProof = null;
|
|
@@ -9659,6 +10226,7 @@ var require_passkeyAuth = __commonJS({
|
|
|
9659
10226
|
}, get default() {
|
|
9660
10227
|
return _default;
|
|
9661
10228
|
} });
|
|
10229
|
+
var _pkce = require_pkce();
|
|
9662
10230
|
function _define_property(obj, key, value) {
|
|
9663
10231
|
if (key in obj) {
|
|
9664
10232
|
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
@@ -9706,8 +10274,12 @@ var require_passkeyAuth = __commonJS({
|
|
|
9706
10274
|
}
|
|
9707
10275
|
const challenge = options.challenge || crypto.getRandomValues(new Uint8Array(32));
|
|
9708
10276
|
const userName = options.userName || this.userName || "user@example.com";
|
|
9709
|
-
const userId = options.userId || this.userId || "user_" +
|
|
9710
|
-
const
|
|
10277
|
+
const userId = options.userId || this.userId || "user_" + (0, _pkce.generateRandomState)(12);
|
|
10278
|
+
const authenticatorSelection = { userVerification: "preferred", residentKey: "preferred" };
|
|
10279
|
+
if (options.authenticatorAttachment) {
|
|
10280
|
+
authenticatorSelection.authenticatorAttachment = options.authenticatorAttachment;
|
|
10281
|
+
}
|
|
10282
|
+
const credential = await navigator.credentials.create({ publicKey: { challenge, rp: { name: this.rpName, id: this.rpId }, user: { id: new TextEncoder().encode(userId), name: userName, displayName: this.userDisplayName || userName }, pubKeyCredParams: [{ alg: -7, type: "public-key" }, { alg: -257, type: "public-key" }], authenticatorSelection, timeout: 6e4, attestation: "none" } });
|
|
9711
10283
|
return credential;
|
|
9712
10284
|
}
|
|
9713
10285
|
async signIn() {
|
|
@@ -10421,9 +10993,9 @@ var require_mappings = __commonJS({
|
|
|
10421
10993
|
_export(exports2, { get providerToButtonMap() {
|
|
10422
10994
|
return providerToButtonMap2;
|
|
10423
10995
|
}, get providerToServiceMap() {
|
|
10424
|
-
return
|
|
10996
|
+
return providerToServiceMap2;
|
|
10425
10997
|
} });
|
|
10426
|
-
var
|
|
10998
|
+
var providerToServiceMap2 = { base: "base", jwt: "jwt", google: "jwt", kakao: "jwt", naver: "jwt", web3: "base", github: "jwt", apple: "jwt", discord: "jwt", line: "jwt", meta: "jwt", facebook: "jwt", world: "base", passkey: "base" };
|
|
10427
10999
|
var providerToButtonMap2 = { base: "none", jwt: "none", google: "google", kakao: "kakao", naver: "naver", web3: "web3", github: "github", apple: "apple", discord: "discord", line: "line", meta: "meta", facebook: "facebook", world: "world", passkey: "passkey" };
|
|
10428
11000
|
}
|
|
10429
11001
|
});
|
|
@@ -10609,6 +11181,7 @@ var require_http = __commonJS({
|
|
|
10609
11181
|
refreshQueue = [];
|
|
10610
11182
|
};
|
|
10611
11183
|
const reqInterceptorId = axiosInstance.interceptors.request.use(async (config) => {
|
|
11184
|
+
config.headers = config.headers || {};
|
|
10612
11185
|
const token = authClient.getAccessToken();
|
|
10613
11186
|
if (token && !config.headers[headerName]) {
|
|
10614
11187
|
config.headers[headerName] = `${tokenPrefix}${token}`;
|
|
@@ -10645,6 +11218,7 @@ var require_http = __commonJS({
|
|
|
10645
11218
|
return new Promise((resolve, reject) => {
|
|
10646
11219
|
refreshQueue.push((token) => {
|
|
10647
11220
|
if (token) {
|
|
11221
|
+
originalRequest.headers = originalRequest.headers || {};
|
|
10648
11222
|
originalRequest.headers[headerName] = `${tokenPrefix}${token}`;
|
|
10649
11223
|
resolve(axiosInstance(originalRequest));
|
|
10650
11224
|
} else {
|
|
@@ -10659,6 +11233,7 @@ var require_http = __commonJS({
|
|
|
10659
11233
|
isRefreshing = false;
|
|
10660
11234
|
processQueue(newToken);
|
|
10661
11235
|
if (newToken) {
|
|
11236
|
+
originalRequest.headers = originalRequest.headers || {};
|
|
10662
11237
|
originalRequest.headers[headerName] = `${tokenPrefix}${newToken}`;
|
|
10663
11238
|
return axiosInstance(originalRequest);
|
|
10664
11239
|
} else {
|
|
@@ -10789,14 +11364,14 @@ var require_authCore = __commonJS({
|
|
|
10789
11364
|
getWebComponentAPI() {
|
|
10790
11365
|
return { addAuthEventListener: _customAuth.addAuthEventListener, removeAuthEventListener: _customAuth.removeAuthEventListener, dispatchAuthEvent: _customAuth.dispatchAuthEvent, watchAuthState: this.serviceInstance.watchAuthState.bind(this.serviceInstance) };
|
|
10791
11366
|
}
|
|
10792
|
-
constructor({ providerType = "base", secret = "isa-auth-secret", storage = "memory", storagePrefix = "" } = {}) {
|
|
11367
|
+
constructor({ providerType = "base", serviceType: explicitServiceType, secret = "isa-auth-secret", storage = "memory", storagePrefix = "" } = {}) {
|
|
10793
11368
|
_define_property(this, "provider", void 0);
|
|
10794
11369
|
_define_property(this, "button", void 0);
|
|
10795
11370
|
_define_property(this, "serviceInstance", void 0);
|
|
10796
11371
|
_define_property(this, "lifecycle", void 0);
|
|
10797
11372
|
(0, _store.configureStorage)({ type: storage, prefix: storagePrefix });
|
|
10798
|
-
var
|
|
10799
|
-
const serviceType = (
|
|
11373
|
+
var _ref;
|
|
11374
|
+
const serviceType = (_ref = explicitServiceType !== null && explicitServiceType !== void 0 ? explicitServiceType : _mappings.providerToServiceMap[providerType]) !== null && _ref !== void 0 ? _ref : "base";
|
|
10800
11375
|
var _providerToButtonMap_providerType;
|
|
10801
11376
|
const buttonType = (_providerToButtonMap_providerType = _mappings.providerToButtonMap[providerType]) !== null && _providerToButtonMap_providerType !== void 0 ? _providerToButtonMap_providerType : "none";
|
|
10802
11377
|
const isProviderRequired = providerType !== "base" && providerType !== "jwt";
|
|
@@ -10905,6 +11480,7 @@ __export(index_exports, {
|
|
|
10905
11480
|
evaluateGuard: () => import_isa_auth_core.evaluateGuard,
|
|
10906
11481
|
generateCodeChallenge: () => import_isa_auth_core.generateCodeChallenge,
|
|
10907
11482
|
generateCodeVerifier: () => import_isa_auth_core.generateCodeVerifier,
|
|
11483
|
+
generateRandomState: () => import_isa_auth_core.generateRandomState,
|
|
10908
11484
|
getAccessToken: () => import_isa_auth_core.getAccessToken,
|
|
10909
11485
|
getAuthInfo: () => import_isa_auth_core.getAuthInfo,
|
|
10910
11486
|
getAuthState: () => import_isa_auth_core.getAuthState,
|
|
@@ -10915,9 +11491,11 @@ __export(index_exports, {
|
|
|
10915
11491
|
getTokenFromHeader: () => import_isa_auth_core.getTokenFromHeader,
|
|
10916
11492
|
getTokenPayload: () => import_isa_auth_core.getTokenPayload,
|
|
10917
11493
|
getTokenTimeRemaining: () => import_isa_auth_core.getTokenTimeRemaining,
|
|
11494
|
+
handleOAuthCallback: () => import_isa_auth_core.handleOAuthCallback,
|
|
10918
11495
|
identityProviders: () => import_isa_auth_core.identityProviders,
|
|
10919
11496
|
isExpiredToken: () => import_isa_auth_core.isExpiredToken,
|
|
10920
11497
|
matchPermissionRule: () => import_isa_auth_core.matchPermissionRule,
|
|
11498
|
+
openOAuthPopup: () => import_isa_auth_core.openOAuthPopup,
|
|
10921
11499
|
parseOAuthCallback: () => import_isa_auth_core.parseOAuthCallback,
|
|
10922
11500
|
renderers: () => render_exports,
|
|
10923
11501
|
resolveInheritedRoles: () => import_isa_auth_core.resolveInheritedRoles,
|
|
@@ -10925,6 +11503,8 @@ __export(index_exports, {
|
|
|
10925
11503
|
socialProviders: () => import_isa_auth_core.socialProviders,
|
|
10926
11504
|
subscribeSelector: () => import_isa_auth_core.subscribeSelector,
|
|
10927
11505
|
updateAuthInfo: () => import_isa_auth_core.updateAuthInfo,
|
|
11506
|
+
useIsaAuth: () => useIsaAuth,
|
|
11507
|
+
waitForOAuthPopupMessage: () => import_isa_auth_core.waitForOAuthPopupMessage,
|
|
10928
11508
|
web3Providers: () => import_isa_auth_core.web3Providers
|
|
10929
11509
|
});
|
|
10930
11510
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -11180,6 +11760,7 @@ function registerWebComponent() {
|
|
|
11180
11760
|
this.dispatchEvent(new CustomEvent("isa-auth-click", { bubbles: true }));
|
|
11181
11761
|
}
|
|
11182
11762
|
});
|
|
11763
|
+
this.innerHTML = "";
|
|
11183
11764
|
this.appendChild(button);
|
|
11184
11765
|
}
|
|
11185
11766
|
}
|
|
@@ -11187,17 +11768,23 @@ function registerWebComponent() {
|
|
|
11187
11768
|
}
|
|
11188
11769
|
|
|
11189
11770
|
// src/render/react.ts
|
|
11190
|
-
function createReactAuthButton(authInstance) {
|
|
11771
|
+
function createReactAuthButton(authInstance, reactInstance) {
|
|
11191
11772
|
return function IsaAuthButton(props) {
|
|
11192
11773
|
var _a;
|
|
11193
11774
|
const { provider, label, className, style, onSuccess, onError, children } = props;
|
|
11194
11775
|
const targetAuth = props.auth || authInstance;
|
|
11776
|
+
if (!targetAuth) {
|
|
11777
|
+
console.warn("[ISA-AUTH] IsaAuth instance is required for IsaAuthButton.");
|
|
11778
|
+
return null;
|
|
11779
|
+
}
|
|
11195
11780
|
if (typeof window === "undefined") {
|
|
11196
11781
|
return null;
|
|
11197
11782
|
}
|
|
11198
|
-
const React = window.React;
|
|
11783
|
+
const React = reactInstance || globalThis.React || (typeof window !== "undefined" ? window.React : void 0);
|
|
11199
11784
|
if (!React) {
|
|
11200
|
-
console.warn(
|
|
11785
|
+
console.warn(
|
|
11786
|
+
"[ISA-AUTH] React is required to render IsaAuthButton. Pass your React instance as createReactAuthButton(auth, React)."
|
|
11787
|
+
);
|
|
11201
11788
|
return null;
|
|
11202
11789
|
}
|
|
11203
11790
|
const handleClick = async () => {
|
|
@@ -11235,8 +11822,48 @@ function createReactAuthButton(authInstance) {
|
|
|
11235
11822
|
"data-provider": provider
|
|
11236
11823
|
},
|
|
11237
11824
|
iconElement,
|
|
11238
|
-
React.createElement(
|
|
11825
|
+
React.createElement(
|
|
11826
|
+
"span",
|
|
11827
|
+
null,
|
|
11828
|
+
children || label || data.text || `Sign in with ${provider}`
|
|
11829
|
+
)
|
|
11830
|
+
);
|
|
11831
|
+
};
|
|
11832
|
+
}
|
|
11833
|
+
function useIsaAuth(auth, reactInstance) {
|
|
11834
|
+
const React = reactInstance || globalThis.React || (typeof window !== "undefined" ? window.React : void 0);
|
|
11835
|
+
if (!React) {
|
|
11836
|
+
throw new Error(
|
|
11837
|
+
"[ISA-AUTH] React instance must be provided or globally available to use useIsaAuth(). Pass React as useIsaAuth(auth, React)."
|
|
11239
11838
|
);
|
|
11839
|
+
}
|
|
11840
|
+
const service = auth.core.getService();
|
|
11841
|
+
const [isAuthenticated, setIsAuthenticated] = React.useState(auth.isAuthenticated());
|
|
11842
|
+
const [user, setUser] = React.useState(service.getAuthInfo());
|
|
11843
|
+
const [token, setToken] = React.useState(auth.getAccessToken());
|
|
11844
|
+
React.useEffect(() => {
|
|
11845
|
+
const syncState = () => {
|
|
11846
|
+
setIsAuthenticated(auth.isAuthenticated());
|
|
11847
|
+
setUser(service.getAuthInfo());
|
|
11848
|
+
setToken(auth.getAccessToken());
|
|
11849
|
+
};
|
|
11850
|
+
const unsubState = auth.subscribe(syncState);
|
|
11851
|
+
const unsubInfo = service.watchAuthInfo(syncState);
|
|
11852
|
+
return () => {
|
|
11853
|
+
if (typeof unsubState === "function") unsubState();
|
|
11854
|
+
if (typeof unsubInfo === "function") unsubInfo();
|
|
11855
|
+
};
|
|
11856
|
+
}, [auth, service]);
|
|
11857
|
+
return {
|
|
11858
|
+
isAuthenticated,
|
|
11859
|
+
user,
|
|
11860
|
+
token,
|
|
11861
|
+
signIn: (provider) => auth.signIn(provider),
|
|
11862
|
+
signOut: () => auth.signOut(),
|
|
11863
|
+
getAccessToken: () => auth.getAccessToken(),
|
|
11864
|
+
getUserInfo: () => auth.getUserInfo(),
|
|
11865
|
+
can: (permission, matchAll = true) => auth.can(permission, matchAll),
|
|
11866
|
+
is: (role, matchAll = false) => auth.is(role, matchAll)
|
|
11240
11867
|
};
|
|
11241
11868
|
}
|
|
11242
11869
|
|
|
@@ -11261,8 +11888,16 @@ var IsaAuth = class {
|
|
|
11261
11888
|
const firstMultiKey = multiProviders ? Object.keys(multiProviders)[0] : void 0;
|
|
11262
11889
|
const primaryProvider = provider || firstMultiKey || "base";
|
|
11263
11890
|
this.providerType = primaryProvider;
|
|
11891
|
+
const allConfiguredProviders = /* @__PURE__ */ new Set([
|
|
11892
|
+
primaryProvider,
|
|
11893
|
+
...multiProviders ? Object.keys(multiProviders) : []
|
|
11894
|
+
]);
|
|
11895
|
+
const hasJwtProvider = Array.from(allConfiguredProviders).some(
|
|
11896
|
+
(p) => import_isa_auth_core.providerToServiceMap[p] === "jwt"
|
|
11897
|
+
);
|
|
11264
11898
|
this.core = new import_isa_auth_core.default({
|
|
11265
11899
|
providerType: primaryProvider,
|
|
11900
|
+
serviceType: hasJwtProvider ? "jwt" : void 0,
|
|
11266
11901
|
secret,
|
|
11267
11902
|
storage,
|
|
11268
11903
|
storagePrefix
|
|
@@ -11307,6 +11942,8 @@ var IsaAuth = class {
|
|
|
11307
11942
|
if (type === "google") {
|
|
11308
11943
|
return new ProviderClass({
|
|
11309
11944
|
clientId,
|
|
11945
|
+
redirectUri: callbackUrl,
|
|
11946
|
+
scope,
|
|
11310
11947
|
callback: (token) => {
|
|
11311
11948
|
this.setAccessToken(token);
|
|
11312
11949
|
return token;
|
|
@@ -11447,8 +12084,26 @@ var IsaAuth = class {
|
|
|
11447
12084
|
}
|
|
11448
12085
|
signOut() {
|
|
11449
12086
|
this.stopAutoRefresh();
|
|
12087
|
+
for (const instance of this.providerInstances.values()) {
|
|
12088
|
+
if (instance && instance !== this.providerInstance && typeof instance.signOut === "function") {
|
|
12089
|
+
try {
|
|
12090
|
+
instance.signOut();
|
|
12091
|
+
} catch {
|
|
12092
|
+
}
|
|
12093
|
+
}
|
|
12094
|
+
}
|
|
11450
12095
|
this.authProvider.signOut();
|
|
11451
12096
|
}
|
|
12097
|
+
/**
|
|
12098
|
+
* Handles incoming OAuth redirect or popup callbacks.
|
|
12099
|
+
* If running inside an authentication popup, communicates payload back to opener and closes popup.
|
|
12100
|
+
*/
|
|
12101
|
+
static handleCallback(options) {
|
|
12102
|
+
return (0, import_isa_auth_core.handleOAuthCallback)(options);
|
|
12103
|
+
}
|
|
12104
|
+
handleCallback(options) {
|
|
12105
|
+
return (0, import_isa_auth_core.handleOAuthCallback)(options);
|
|
12106
|
+
}
|
|
11452
12107
|
async refresh(refreshFn) {
|
|
11453
12108
|
return await this.authProvider.refresh(refreshFn);
|
|
11454
12109
|
}
|
|
@@ -11611,6 +12266,9 @@ var IsaAuth = class {
|
|
|
11611
12266
|
subscribe(callback) {
|
|
11612
12267
|
return this.authProvider.watchAuthState(callback);
|
|
11613
12268
|
}
|
|
12269
|
+
watchAuthState(callback) {
|
|
12270
|
+
return this.subscribe(callback);
|
|
12271
|
+
}
|
|
11614
12272
|
};
|
|
11615
12273
|
var index_default = IsaAuth;
|
|
11616
12274
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -11654,6 +12312,7 @@ var index_default = IsaAuth;
|
|
|
11654
12312
|
evaluateGuard,
|
|
11655
12313
|
generateCodeChallenge,
|
|
11656
12314
|
generateCodeVerifier,
|
|
12315
|
+
generateRandomState,
|
|
11657
12316
|
getAccessToken,
|
|
11658
12317
|
getAuthInfo,
|
|
11659
12318
|
getAuthState,
|
|
@@ -11664,9 +12323,11 @@ var index_default = IsaAuth;
|
|
|
11664
12323
|
getTokenFromHeader,
|
|
11665
12324
|
getTokenPayload,
|
|
11666
12325
|
getTokenTimeRemaining,
|
|
12326
|
+
handleOAuthCallback,
|
|
11667
12327
|
identityProviders,
|
|
11668
12328
|
isExpiredToken,
|
|
11669
12329
|
matchPermissionRule,
|
|
12330
|
+
openOAuthPopup,
|
|
11670
12331
|
parseOAuthCallback,
|
|
11671
12332
|
renderers,
|
|
11672
12333
|
resolveInheritedRoles,
|
|
@@ -11674,6 +12335,8 @@ var index_default = IsaAuth;
|
|
|
11674
12335
|
socialProviders,
|
|
11675
12336
|
subscribeSelector,
|
|
11676
12337
|
updateAuthInfo,
|
|
12338
|
+
useIsaAuth,
|
|
12339
|
+
waitForOAuthPopupMessage,
|
|
11677
12340
|
web3Providers
|
|
11678
12341
|
});
|
|
11679
12342
|
/*! Bundled license information:
|