File tree Expand file tree Collapse file tree 5 files changed +18
-11
lines changed Expand file tree Collapse file tree 5 files changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ function runAuth() {
41
41
} ,
42
42
addUserSignedOut : ( ) => { } ,
43
43
} ,
44
+ //your key customization of oidc redirect callback
45
+ redirectUriKey : "CUSTOM_REDIRECT_URI" ,
44
46
} ) ;
45
47
}
46
48
Original file line number Diff line number Diff line change 1
1
import { UserManager , UserManagerEvents } from "oidc-client-ts" ;
2
2
import { unref } from "vue" ;
3
+ import { oidcRedirectUriKey } from "./keys" ;
3
4
import { useOidcStore } from "./store" ;
4
5
import { inlineOidcEvents } from "./store/events" ;
5
6
import { VueOidcSettings } from "./store/index" ;
@@ -34,12 +35,17 @@ export interface CreateOidcOptions {
34
35
* refresh token
35
36
*/
36
37
refreshToken ?: RefreshTokenConfig ;
38
+ /**
39
+ * key of oidc redirect callback
40
+ */
41
+ redirectUriKey ?: string ;
37
42
}
38
43
39
44
export function createOidc ( options : CreateOidcOptions ) {
40
45
const _options = { ...inlineCreateOidcOptions , ...options } ;
41
46
const { oidcSettings, auth, refreshToken } = _options ;
42
47
const events = { ...inlineOidcEvents , ...options . events } ;
48
+ oidcRedirectUriKey . value = options . redirectUriKey || oidcRedirectUriKey . value ;
43
49
44
50
unref ( state ) . settings = _options ;
45
51
unref ( state ) . oidcSettings = oidcSettings ;
Original file line number Diff line number Diff line change 1
- export const OIDC_REDIRECT_URI = "OIDC_REDIRECT_URI" ;
1
+ import { ref } from "vue" ;
2
+
3
+ export const oidcRedirectUriKey = ref ( "OIDC_REDIRECT_URI" ) ;
Original file line number Diff line number Diff line change 1
- import { OIDC_REDIRECT_URI } from "@/keys" ;
1
+ import { oidcRedirectUriKey } from "@/keys" ;
2
2
import { MaybeNull } from "@/types" ;
3
- import { useStorage , type RemovableRef } from "@vueuse/core" ;
3
+ import { useStorage } from "@vueuse/core" ;
4
4
import {
5
5
User ,
6
6
UserManager ,
@@ -39,11 +39,6 @@ export interface OidcActions {
39
39
removeUser ( ) : void ;
40
40
}
41
41
42
- export const storage : RemovableRef < string > = useStorage < string > (
43
- OIDC_REDIRECT_URI ,
44
- ""
45
- ) ;
46
-
47
42
const state : UnwrapNestedRefs < OidcState > = reactive < OidcState > ( {
48
43
settings : null ,
49
44
oidcSettings : null ,
@@ -54,7 +49,7 @@ const state: UnwrapNestedRefs<OidcState> = reactive<OidcState>({
54
49
hasExpiresAt : computed (
55
50
( ) => Date . now ( ) / 1000 > state . user ?. expires_at ! || false
56
51
) ,
57
- redirect_uri : storage . value ,
52
+ redirect_uri : useStorage < string > ( oidcRedirectUriKey . value , "" ) . value ,
58
53
} ) ;
59
54
60
55
const actions : OidcActions = {
Original file line number Diff line number Diff line change 1
- import { toValue } from "@vueuse/core" ;
1
+ import { toValue , useStorage } from "@vueuse/core" ;
2
2
import {
3
3
SigninRedirectArgs ,
4
4
SigninSilentArgs ,
5
5
SignoutRedirectArgs ,
6
6
User ,
7
7
} from "oidc-client-ts" ;
8
8
import { unref } from "vue" ;
9
- import { storage , useOidcStore } from "./store" ;
9
+ import { oidcRedirectUriKey } from "./keys" ;
10
+ import { useOidcStore } from "./store" ;
10
11
import { isPathOfCallback } from "./utils" ;
11
12
12
13
const { state, actions } = useOidcStore ( ) ;
@@ -36,6 +37,7 @@ function signoutRedirect(arg?: SignoutRedirectArgs) {
36
37
async function autoAuthenticate ( uri : string = "" ) {
37
38
let timer : NodeJS . Timer | null = null ;
38
39
const user = ( await unref ( state ) . userManager ?. getUser ( ) ) || unref ( state ) . user ;
40
+ const storage = useStorage < string > ( oidcRedirectUriKey . value , "" ) ;
39
41
40
42
//if the user and pathCallback is not, then we can authenticate
41
43
if ( ! user && ! isPathOfCallback ( ) ) {
You can’t perform that action at this time.
0 commit comments