@alfabit/keycloak 0.0.7 → 0.0.9
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 +23 -11
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Keycloak, { type KeycloakInitOptions } from 'keycloak-js';
|
|
2
2
|
import { inject, reactive, readonly, type Ref, ref } from 'vue';
|
|
3
3
|
import { postWebLogin } from '../api/wallet/endpoints';
|
|
4
|
-
import { AppNameEnum, APP_NAME, IS_TELEGRAM_MINI_APP, KEYCLOAK_LOGIN_REQUIRED, OPENID_CLIENT_ID, OPENID_REALM, OPENID_URL } from '@alfabit/constants';
|
|
4
|
+
import { AppNameEnum, APP_NAME, IS_TELEGRAM_MINI_APP, KEYCLOAK_LOGIN_REQUIRED, OPENID_CLIENT_ID, OPENID_REALM, OPENID_URL, LocationEnum } from '@alfabit/constants';
|
|
5
5
|
|
|
6
6
|
export type TIdpHint = 'email' | 'google' | 'apple';
|
|
7
7
|
|
|
@@ -33,10 +33,11 @@ const keycloak = ref<Keycloak | null>(null);
|
|
|
33
33
|
const isAuth = ref(false);
|
|
34
34
|
const checkAuth = ref(false);
|
|
35
35
|
const keycloakUserData = ref<Keycloak.KeycloakTokenParsed | null>(null);
|
|
36
|
+
const locale = ref('en');
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
38
|
+
export const setKeycloakLocale = (newLocale: LocationEnum) => {
|
|
39
|
+
locale.value = newLocale;
|
|
40
|
+
};
|
|
40
41
|
|
|
41
42
|
const isInitialized = ref(false);
|
|
42
43
|
|
|
@@ -44,20 +45,17 @@ const getUrl = (dontChangeRedirectUri = false, keycloakRedirectUriIsLogout: stri
|
|
|
44
45
|
const url = new URL(window.location.href);
|
|
45
46
|
const searchParams = new URLSearchParams(window.location.search);
|
|
46
47
|
|
|
47
|
-
console.log('getUrl', {
|
|
48
|
-
dontChangeRedirectUri,
|
|
49
|
-
keycloakRedirectUriIsLogout,
|
|
50
|
-
redirect_uri: searchParams.get('redirect_uri'),
|
|
51
|
-
});
|
|
52
|
-
|
|
53
48
|
if (searchParams.has('redirect_uri')) {
|
|
54
49
|
const redirectUri = searchParams.get('redirect_uri');
|
|
55
50
|
if (!!redirectUri) return redirectUri;
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
// если в роуте в meta есть параметр keycloakRedirectUriIsLogout - возвращаем его
|
|
59
|
-
if (!!keycloakRedirectUriIsLogout && typeof keycloakRedirectUriIsLogout === 'string') return keycloakRedirectUriIsLogout
|
|
54
|
+
if (!!keycloakRedirectUriIsLogout && typeof keycloakRedirectUriIsLogout === 'string') return `${locale.value}/${keycloakRedirectUriIsLogout}`;
|
|
60
55
|
|
|
56
|
+
console.log({
|
|
57
|
+
dontChangeRedirectUri,
|
|
58
|
+
});
|
|
61
59
|
// если в $route.meta (который передаем из родительского приложения) есть параметр dontChangeRedirectUri - то из адреса ну нужно удалять или добавлять /user
|
|
62
60
|
// если нет - то ничего не делать
|
|
63
61
|
|
|
@@ -165,6 +163,7 @@ export const getAuthMethods = ({ dontChangeRedirectUri = ref(false), keycloakRed
|
|
|
165
163
|
keycloak.value.login({
|
|
166
164
|
redirectUri: redirectUri ?? getUrl(dontChangeRedirectUri.value, keycloakRedirectUriIsLogout.value),
|
|
167
165
|
loginHint: email ?? '',
|
|
166
|
+
locale: locale.value,
|
|
168
167
|
});
|
|
169
168
|
} else {
|
|
170
169
|
console.warn('Keycloak not defined! #login');
|
|
@@ -174,6 +173,12 @@ export const getAuthMethods = ({ dontChangeRedirectUri = ref(false), keycloakRed
|
|
|
174
173
|
if (keycloak.value) {
|
|
175
174
|
clearTokens();
|
|
176
175
|
setTimeout(() => {
|
|
176
|
+
console.log('logout', {
|
|
177
|
+
keycloakRedirectUriIsLogout: keycloakRedirectUriIsLogout.value,
|
|
178
|
+
dontChangeRedirectUri: dontChangeRedirectUri.value,
|
|
179
|
+
redirectUri: redirectUri ?? getUrl(dontChangeRedirectUri.value, keycloakRedirectUriIsLogout.value),
|
|
180
|
+
});
|
|
181
|
+
|
|
177
182
|
keycloak.value &&
|
|
178
183
|
keycloak.value.logout({
|
|
179
184
|
redirectUri: redirectUri ?? getUrl(dontChangeRedirectUri.value, keycloakRedirectUriIsLogout.value),
|
|
@@ -188,6 +193,7 @@ export const getAuthMethods = ({ dontChangeRedirectUri = ref(false), keycloakRed
|
|
|
188
193
|
keycloak.value.register({
|
|
189
194
|
redirectUri: redirectUri ?? getUrl(dontChangeRedirectUri.value),
|
|
190
195
|
loginHint: email ?? '',
|
|
196
|
+
locale: locale.value,
|
|
191
197
|
});
|
|
192
198
|
} else {
|
|
193
199
|
console.warn('Keycloak not defined! #register');
|
|
@@ -210,6 +216,7 @@ export const getAuthMethods = ({ dontChangeRedirectUri = ref(false), keycloakRed
|
|
|
210
216
|
keycloak.value.login({
|
|
211
217
|
redirectUri: redirectUri ?? getUrl(dontChangeRedirectUri.value),
|
|
212
218
|
idpHint: 'apple',
|
|
219
|
+
locale: locale.value,
|
|
213
220
|
});
|
|
214
221
|
} else {
|
|
215
222
|
console.warn('Keycloak not defined! #loginWithApple');
|
|
@@ -220,6 +227,7 @@ export const getAuthMethods = ({ dontChangeRedirectUri = ref(false), keycloakRed
|
|
|
220
227
|
keycloak.value.login({
|
|
221
228
|
redirectUri: redirectUri ?? getUrl(dontChangeRedirectUri.value),
|
|
222
229
|
idpHint: 'telegram',
|
|
230
|
+
locale: locale.value,
|
|
223
231
|
});
|
|
224
232
|
} else {
|
|
225
233
|
console.warn('Keycloak not defined! #loginWithTelegram');
|
|
@@ -342,6 +350,10 @@ export async function initKeycloak() {
|
|
|
342
350
|
clientId: OPENID_CLIENT_ID,
|
|
343
351
|
});
|
|
344
352
|
|
|
353
|
+
console.log({
|
|
354
|
+
keycloak: keycloak.value,
|
|
355
|
+
});
|
|
356
|
+
|
|
345
357
|
const isNeedAuth = !!getToken() && !isRtExp();
|
|
346
358
|
|
|
347
359
|
// window.opener - если находимся в popup (но не в passport), то 100% уже авторизованы и можно поставить login-required
|