@@ -102,25 +102,25 @@ const getOAuth2AuthorizationCode = (request, codeChallenge, collectionUid) => {
102
102
const { oauth2 } = request ;
103
103
const { callbackUrl, clientId, authorizationUrl, scope, state, pkce } = oauth2 ;
104
104
105
- let oauth2QueryParams =
106
- ( authorizationUrl . indexOf ( '?' ) > - 1 ? '&' : '?' ) + `client_id=${ clientId } &response_type=code` ;
105
+ const authorizationUrlWithQueryParams = new URL ( authorizationUrl ) ;
106
+ authorizationUrlWithQueryParams . searchParams . append ( 'response_type' , 'code' ) ;
107
+ authorizationUrlWithQueryParams . searchParams . append ( 'client_id' , clientId ) ;
107
108
if ( callbackUrl ) {
108
- oauth2QueryParams += `& redirect_uri= ${ callbackUrl } ` ;
109
+ authorizationUrlWithQueryParams . searchParams . append ( ' redirect_uri' , callbackUrl ) ;
109
110
}
110
111
if ( scope ) {
111
- oauth2QueryParams += `& scope= ${ scope } ` ;
112
+ authorizationUrlWithQueryParams . searchParams . append ( 'scope' , scope ) ;
112
113
}
113
114
if ( pkce ) {
114
- oauth2QueryParams += `&code_challenge=${ codeChallenge } &code_challenge_method=S256` ;
115
+ authorizationUrlWithQueryParams . searchParams . append ( 'code_challenge' , codeChallenge ) ;
116
+ authorizationUrlWithQueryParams . searchParams . append ( 'code_challenge_method' , 'S256' ) ;
115
117
}
116
118
if ( state ) {
117
- oauth2QueryParams += `& state= ${ state } ` ;
119
+ authorizationUrlWithQueryParams . searchParams . append ( 'state' , state ) ;
118
120
}
119
-
120
- const authorizationUrlWithQueryParams = authorizationUrl + oauth2QueryParams ;
121
121
try {
122
122
const { authorizationCode } = await authorizeUserInWindow ( {
123
- authorizeUrl : authorizationUrlWithQueryParams ,
123
+ authorizeUrl : authorizationUrlWithQueryParams . toString ( ) ,
124
124
callbackUrl,
125
125
session : oauth2Store . getSessionIdOfCollection ( collectionUid )
126
126
} ) ;
@@ -210,21 +210,21 @@ const oauth2AuthorizeWithImplicitFlow = async (request, collectionUid) => {
210
210
return new Promise ( async ( resolve , reject ) => {
211
211
const { oauth2 } = request ;
212
212
const { callbackUrl, authorizationUrl, clientId, scope, state } = oauth2 ;
213
- let oauth2QueryParams =
214
- ( authorizationUrl . indexOf ( '?' ) > - 1 ? '&' : '?' ) + `client_id=${ clientId } &response_type=token` ;
213
+ const authorizationUrlWithQueryParams = new URL ( authorizationUrl ) ;
214
+ authorizationUrlWithQueryParams . searchParams . append ( 'response_type' , 'token' ) ;
215
+ authorizationUrlWithQueryParams . searchParams . append ( 'client_id' , clientId ) ;
215
216
if ( callbackUrl ) {
216
- oauth2QueryParams += `& redirect_uri= ${ callbackUrl } ` ;
217
+ authorizationUrlWithQueryParams . searchParams . append ( ' redirect_uri' , callbackUrl ) ;
217
218
}
218
219
if ( scope ) {
219
- oauth2QueryParams += `& scope= ${ scope } ` ;
220
+ authorizationUrlWithQueryParams . searchParams . append ( 'scope' , scope ) ;
220
221
}
221
222
if ( state ) {
222
- oauth2QueryParams += `& state= ${ state } ` ;
223
+ authorizationUrlWithQueryParams . searchParams . append ( 'state' , state ) ;
223
224
}
224
- const authorizationUrlWithQueryParams = authorizationUrl + oauth2QueryParams ;
225
225
try {
226
226
const { credentials } = await authorizeUserInWindowImplicit ( {
227
- authorizeUrl : authorizationUrlWithQueryParams ,
227
+ authorizeUrl : authorizationUrlWithQueryParams . toString ( ) ,
228
228
callbackUrl : callbackUrl ,
229
229
session : oauth2Store . getSessionIdOfCollection ( collectionUid )
230
230
} ) ;
0 commit comments