bt-core-app 1.3.2 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bt-core-app.js +3010 -3014
- package/dist/composables/auth.d.ts +2 -2
- package/package.json +1 -1
- package/src/composables/auth.ts +22 -26
|
@@ -36,7 +36,7 @@ export interface CreateAuthOptions {
|
|
|
36
36
|
/**OVERRIDES DEFAULT. use the given code and generate the url to convert to an access token */
|
|
37
37
|
getTokenUrl?: (code: string, redirect_uri: string, grant_type: string, client_id: string) => string;
|
|
38
38
|
/**OVERRIDES DEFAULT. */
|
|
39
|
-
getToken?: () => Promise<void>;
|
|
39
|
+
getToken?: (code?: string, state?: string) => Promise<void>;
|
|
40
40
|
oauthGrantType?: string;
|
|
41
41
|
oauthClientID?: string;
|
|
42
42
|
/**sets current credentials on top of default function
|
|
@@ -57,7 +57,7 @@ export interface BTAuth {
|
|
|
57
57
|
doShowByNav: (navName?: string | AuthItem, includeChildren?: boolean) => boolean;
|
|
58
58
|
getAuthorizeUrl: (redirectPath?: string) => string;
|
|
59
59
|
getTimeZone: () => string;
|
|
60
|
-
getToken: () => Promise<void>;
|
|
60
|
+
getToken: (code?: string, state?: string) => Promise<void>;
|
|
61
61
|
login: (redirectPath?: string) => void;
|
|
62
62
|
logout: (navNameRedirect?: string) => void;
|
|
63
63
|
setAuth: (jwtToken?: string) => void;
|
package/package.json
CHANGED
package/src/composables/auth.ts
CHANGED
|
@@ -2,9 +2,10 @@ import { appendUrl, isLengthyArray } from '../composables/helpers'
|
|
|
2
2
|
import { DateTime } from 'luxon'
|
|
3
3
|
import { type RemovableRef, useStorage } from '@vueuse/core'
|
|
4
4
|
import { type BTDemo } from '../composables/demo'
|
|
5
|
-
import {
|
|
5
|
+
import { useRouter } from 'vue-router'
|
|
6
6
|
import { toValue } from 'vue'
|
|
7
7
|
import { useAuthUrl } from './urls'
|
|
8
|
+
import { useApi } from './api'
|
|
8
9
|
|
|
9
10
|
export interface AuthItem {
|
|
10
11
|
children?: AuthItem[]
|
|
@@ -48,7 +49,7 @@ export interface CreateAuthOptions {
|
|
|
48
49
|
/**OVERRIDES DEFAULT. use the given code and generate the url to convert to an access token */
|
|
49
50
|
getTokenUrl?: (code: string, redirect_uri: string, grant_type: string, client_id: string) => string
|
|
50
51
|
/**OVERRIDES DEFAULT. */
|
|
51
|
-
getToken?: () => Promise<void>
|
|
52
|
+
getToken?: (code?: string, state?: string) => Promise<void>
|
|
52
53
|
oauthGrantType?: string
|
|
53
54
|
oauthClientID?: string
|
|
54
55
|
/**sets current credentials on top of default function
|
|
@@ -70,7 +71,7 @@ export interface BTAuth {
|
|
|
70
71
|
doShowByNav: (navName?: string | AuthItem, includeChildren?: boolean) => boolean
|
|
71
72
|
getAuthorizeUrl: (redirectPath?: string) => string
|
|
72
73
|
getTimeZone: () => string
|
|
73
|
-
getToken: () => Promise<void>
|
|
74
|
+
getToken: (code?: string, state?: string) => Promise<void>
|
|
74
75
|
login: (redirectPath?: string) => void
|
|
75
76
|
logout: (navNameRedirect?: string) => void
|
|
76
77
|
setAuth: (jwtToken?: string) => void
|
|
@@ -311,13 +312,10 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
|
|
|
311
312
|
}
|
|
312
313
|
|
|
313
314
|
/**defaults to find parameters from route query */
|
|
314
|
-
async function getToken(code?: string, state?: string
|
|
315
|
+
async function getToken(code?: string, state?: string) {
|
|
315
316
|
options.getToken ??= async () => {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
let mCode = code ?? route.query?.code as string
|
|
319
|
-
let mState = state ?? route.query?.state as string
|
|
320
|
-
let mRedirectPath = redirect_path ?? route.query?.redirect_path as string
|
|
317
|
+
let mCode = code
|
|
318
|
+
let mState = state
|
|
321
319
|
let mGrantType = options.oauthGrantType ?? 'authorization_token'
|
|
322
320
|
let mClientID = options.oauthClientID ?? ''
|
|
323
321
|
|
|
@@ -342,27 +340,25 @@ export function createAuth(options: CreateAuthOptions): BTAuth {
|
|
|
342
340
|
formData['redirect_uri'] = `${window.location.origin}/authentication`
|
|
343
341
|
formData['client_id'] = mClientID
|
|
344
342
|
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
body: JSON.stringify(formData)
|
|
343
|
+
const api = useApi()
|
|
344
|
+
const res = await api.post<any>({
|
|
345
|
+
additionalUrl: url,
|
|
346
|
+
data: formData
|
|
350
347
|
})
|
|
351
|
-
|
|
352
|
-
const data = await res.json()
|
|
353
|
-
|
|
354
|
-
setAuth(data.value?.access_token)
|
|
355
348
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
349
|
+
// const res = await fetch(url, {
|
|
350
|
+
// method: 'POST',
|
|
351
|
+
// mode: 'cors',
|
|
352
|
+
// cache: 'no-cache',
|
|
353
|
+
// body: JSON.stringify(formData)
|
|
354
|
+
// })
|
|
355
|
+
|
|
356
|
+
// const data = await res.json()
|
|
357
|
+
|
|
358
|
+
setAuth(res.access_token)
|
|
363
359
|
}
|
|
364
360
|
|
|
365
|
-
return await options.getToken()
|
|
361
|
+
return await options.getToken(code, state)
|
|
366
362
|
}
|
|
367
363
|
|
|
368
364
|
/**if not demoing, then will decrypt the jwtToken and attempt to set credentials */
|