@@ -3,6 +3,10 @@ import { IssuerRouteTypes, LoginOptions, PromptTypes } from "../types";
3
3
import { generateRandomString } from "./generateRandomString" ;
4
4
import { mapLoginMethodParamsForUrl } from "./mapLoginMethodParamsForUrl" ;
5
5
6
+ interface generateAuthUrlConfig {
7
+ disableUrlSanitization : boolean ;
8
+ }
9
+
6
10
/**
7
11
*
8
12
* @param options
@@ -12,7 +16,8 @@ import { mapLoginMethodParamsForUrl } from "./mapLoginMethodParamsForUrl";
12
16
export const generateAuthUrl = async (
13
17
domain : string ,
14
18
type : IssuerRouteTypes = IssuerRouteTypes . login ,
15
- options : LoginOptions ,
19
+ loginOptions : LoginOptions ,
20
+ config ?: generateAuthUrlConfig ,
16
21
) : Promise < {
17
22
url : URL ;
18
23
state : string ;
@@ -23,30 +28,30 @@ export const generateAuthUrl = async (
23
28
const authPath = `${ domain } /oauth2/auth` ;
24
29
const activeStorage = getInsecureStorage ( ) ;
25
30
const searchParams : Record < string , string > = {
26
- client_id : options . clientId ,
27
- response_type : options . responseType || "code" ,
28
- ...mapLoginMethodParamsForUrl ( options ) ,
31
+ client_id : loginOptions . clientId ,
32
+ response_type : loginOptions . responseType || "code" ,
33
+ ...mapLoginMethodParamsForUrl ( loginOptions , config ?. disableUrlSanitization ) ,
29
34
} ;
30
35
31
- if ( ! options . state ) {
32
- options . state = generateRandomString ( 32 ) ;
36
+ if ( ! loginOptions . state ) {
37
+ loginOptions . state = generateRandomString ( 32 ) ;
33
38
}
34
39
if ( activeStorage ) {
35
- activeStorage . setSessionItem ( StorageKeys . state , options . state ) ;
40
+ activeStorage . setSessionItem ( StorageKeys . state , loginOptions . state ) ;
36
41
}
37
- searchParams [ "state" ] = options . state ;
42
+ searchParams [ "state" ] = loginOptions . state ;
38
43
39
- if ( ! options . nonce ) {
40
- options . nonce = generateRandomString ( 16 ) ;
44
+ if ( ! loginOptions . nonce ) {
45
+ loginOptions . nonce = generateRandomString ( 16 ) ;
41
46
}
42
- searchParams [ "nonce" ] = options . nonce ;
47
+ searchParams [ "nonce" ] = loginOptions . nonce ;
43
48
if ( activeStorage ) {
44
- activeStorage . setSessionItem ( StorageKeys . nonce , options . nonce ) ;
49
+ activeStorage . setSessionItem ( StorageKeys . nonce , loginOptions . nonce ) ;
45
50
}
46
51
47
52
let returnCodeVerifier = "" ;
48
- if ( options . codeChallenge ) {
49
- searchParams [ "code_challenge" ] = options . codeChallenge ;
53
+ if ( loginOptions . codeChallenge ) {
54
+ searchParams [ "code_challenge" ] = loginOptions . codeChallenge ;
50
55
} else {
51
56
const { codeVerifier, codeChallenge } = await generatePKCEPair ( ) ;
52
57
returnCodeVerifier = codeVerifier ;
@@ -57,11 +62,11 @@ export const generateAuthUrl = async (
57
62
}
58
63
searchParams [ "code_challenge_method" ] = "S256" ;
59
64
60
- if ( options . codeChallengeMethod ) {
61
- searchParams [ "code_challenge_method" ] = options . codeChallengeMethod ;
65
+ if ( loginOptions . codeChallengeMethod ) {
66
+ searchParams [ "code_challenge_method" ] = loginOptions . codeChallengeMethod ;
62
67
}
63
68
64
- if ( ! options . prompt && type === IssuerRouteTypes . register ) {
69
+ if ( ! loginOptions . prompt && type === IssuerRouteTypes . register ) {
65
70
searchParams [ "prompt" ] = PromptTypes . create ;
66
71
}
67
72
0 commit comments