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