@alfabit/keycloak 0.0.42 → 0.0.43
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/package.json +1 -1
- package/src/composables/use-keycloak.ts +14 -12
package/package.json
CHANGED
|
@@ -82,21 +82,21 @@ const locale = ref('en');
|
|
|
82
82
|
const dontChangeRedirectUri = ref(false);
|
|
83
83
|
const keycloakRedirectUriIsLogout = ref<string | undefined>(undefined);
|
|
84
84
|
|
|
85
|
-
export
|
|
85
|
+
export function setKeycloakLocale(newLocale: LocationEnum) {
|
|
86
86
|
locale.value = newLocale;
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
export
|
|
89
|
+
export function setDontChangeRedirectUri(newDontChangeRedirectUri: boolean) {
|
|
90
90
|
dontChangeRedirectUri.value = newDontChangeRedirectUri;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
export
|
|
93
|
+
export function setKeycloakRedirectUriIsLogout(newKeycloakRedirectUriIsLogout: string | undefined) {
|
|
94
94
|
keycloakRedirectUriIsLogout.value = newKeycloakRedirectUriIsLogout;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
const isInitialized = ref(false);
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
function getUrl(): string {
|
|
100
100
|
const url = new URL(window.location.href);
|
|
101
101
|
const searchParams = new URLSearchParams(window.location.search);
|
|
102
102
|
|
|
@@ -138,8 +138,8 @@ function isMobile() {
|
|
|
138
138
|
return /Mobi|Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
export
|
|
142
|
-
const methods =
|
|
141
|
+
export function getAuthMethods() {
|
|
142
|
+
const methods = {
|
|
143
143
|
async loginPopup(idpHint: TIdpHint, redirectUri?: string) {
|
|
144
144
|
redirectUri = redirectUri ?? getUrl();
|
|
145
145
|
if (isMobile()) {
|
|
@@ -289,7 +289,7 @@ export const getAuthMethods = () => {
|
|
|
289
289
|
console.warn('Keycloak not defined! #configureOtp');
|
|
290
290
|
}
|
|
291
291
|
},
|
|
292
|
-
}
|
|
292
|
+
};
|
|
293
293
|
return methods;
|
|
294
294
|
};
|
|
295
295
|
|
|
@@ -314,9 +314,11 @@ function clearTokens() {
|
|
|
314
314
|
sessionStorage.removeItem(ID_TOKEN_NAME);
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
export
|
|
317
|
+
export function getToken() {
|
|
318
|
+
return (IS_TELEGRAM_MINI_APP && !IS_LOCALHOST ? sessionStorage.getItem(TOKEN_NAME) : localStorage.getItem(TOKEN_NAME)) ?? undefined;
|
|
319
|
+
}
|
|
318
320
|
|
|
319
|
-
|
|
321
|
+
function parseJwt(token: unknown) {
|
|
320
322
|
if (typeof token !== 'string') throw new Error('Invalid JWT format: #1');
|
|
321
323
|
const [headerB64, payloadB64] = token.split('.');
|
|
322
324
|
if (!headerB64 || !payloadB64) throw new Error('Invalid JWT format: #2');
|
|
@@ -333,7 +335,7 @@ const parseJwt = (token: unknown) => {
|
|
|
333
335
|
};
|
|
334
336
|
};
|
|
335
337
|
|
|
336
|
-
export
|
|
338
|
+
export function isAtExp() {
|
|
337
339
|
if (typeof window === 'undefined') return false;
|
|
338
340
|
try {
|
|
339
341
|
return parseJwt(localStorage.getItem(TOKEN_NAME)).isExpired;
|
|
@@ -342,7 +344,7 @@ export const isAtExp = () => {
|
|
|
342
344
|
}
|
|
343
345
|
};
|
|
344
346
|
|
|
345
|
-
export
|
|
347
|
+
export function isRtExp() {
|
|
346
348
|
if (typeof window === 'undefined') return false;
|
|
347
349
|
try {
|
|
348
350
|
// если рт не истек, возвращаем true
|
|
@@ -518,7 +520,7 @@ export async function createKeycloakInit({ keycloakInit }: IKeycliakInit = {}) {
|
|
|
518
520
|
|
|
519
521
|
let _keycloakInit: IUseKeycloak | null = null;
|
|
520
522
|
|
|
521
|
-
export
|
|
523
|
+
export function keycloakInit(dontChangeRedirectUri?: Ref<boolean>, keycloakRedirectUriIsLogout?: Ref<string | undefined>): IUseKeycloak {
|
|
522
524
|
if (_keycloakInit) return _keycloakInit;
|
|
523
525
|
|
|
524
526
|
dontChangeRedirectUri ||= inject('dontChangeRedirectUri', ref(false));
|