@@ -49,26 +49,26 @@ const getOAuth2AuthorizationCode = (request, codeChallenge, collectionUid) => {
49
49
const { oauth2 } = request ;
50
50
const { callbackUrl, clientId, authorizationUrl, scope, state, pkce } = oauth2 ;
51
51
52
- let oauth2QueryParams =
53
- ( authorizationUrl . indexOf ( '?' ) > - 1 ? '&' : '?' ) + `client_id=${ clientId } &response_type=code` ;
52
+ const authorizationUrlWithQueryParams = new URL ( authorizationUrl ) ;
53
+ authorizationUrlWithQueryParams . searchParams . append ( 'response_type' , 'code' ) ;
54
+ authorizationUrlWithQueryParams . searchParams . append ( 'client_id' , clientId ) ;
54
55
if ( callbackUrl ) {
55
- oauth2QueryParams += `& redirect_uri= ${ callbackUrl } ` ;
56
+ authorizationUrlWithQueryParams . searchParams . append ( ' redirect_uri' , callbackUrl ) ;
56
57
}
57
58
if ( scope ) {
58
- oauth2QueryParams += `& scope= ${ scope } ` ;
59
+ authorizationUrlWithQueryParams . searchParams . append ( 'scope' , scope ) ;
59
60
}
60
61
if ( pkce ) {
61
- oauth2QueryParams += `&code_challenge=${ codeChallenge } &code_challenge_method=S256` ;
62
+ authorizationUrlWithQueryParams . searchParams . append ( 'code_challenge' , codeChallenge ) ;
63
+ authorizationUrlWithQueryParams . searchParams . append ( 'code_challenge_method' , 'S256' ) ;
62
64
}
63
65
if ( state ) {
64
- oauth2QueryParams += `& state= ${ state } ` ;
66
+ authorizationUrlWithQueryParams . searchParams . append ( 'state' , state ) ;
65
67
}
66
-
67
- const authorizationUrlWithQueryParams = authorizationUrl + oauth2QueryParams ;
68
68
try {
69
69
const oauth2Store = new Oauth2Store ( ) ;
70
70
const { authorizationCode } = await authorizeUserInWindow ( {
71
- authorizeUrl : authorizationUrlWithQueryParams ,
71
+ authorizeUrl : authorizationUrlWithQueryParams . toString ( ) ,
72
72
callbackUrl,
73
73
session : oauth2Store . getSessionIdOfCollection ( collectionUid )
74
74
} ) ;
0 commit comments