File tree Expand file tree Collapse file tree 3 files changed +19
-13
lines changed Expand file tree Collapse file tree 3 files changed +19
-13
lines changed Original file line number Diff line number Diff line change @@ -415,7 +415,7 @@ export class Connection<S extends Schema = Schema> extends JSForceConnection<S>
415415 }
416416
417417 /**
418- * Executes a HEAD request on the baseUrl to force an auth refresh.
418+ * Executes a GET request on the baseUrl to force an auth refresh.
419419 * This is useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes.
420420 *
421421 * This method issues a request using the current access token to check if it is still valid.
@@ -427,7 +427,13 @@ export class Connection<S extends Schema = Schema> extends JSForceConnection<S>
427427 this . logger . debug ( 'Refreshing auth for org.' ) ;
428428 const requestInfo : HttpRequest = {
429429 url : this . baseUrl ( ) ,
430- method : 'HEAD' ,
430+ /**
431+ * IMPORTANT:
432+ * We do a GET request instead of a HEAD to get the response body.
433+ *
434+ * jsforce relies on the res status code AND body to be able to stop retrying on known invalid scenarios (e.g. API access restricted to a specific CA/ECA)
435+ */
436+ method : 'GET' ,
431437 } ;
432438 await this . request ( requestInfo ) ;
433439 }
Original file line number Diff line number Diff line change @@ -997,21 +997,16 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
997997 }
998998
999999 /**
1000- * Executes a HEAD request on the baseUrl to force an auth refresh.
1000+ * Executes a GET request on the baseUrl to force an auth refresh.
10011001 * This is useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes.
10021002 *
10031003 * This method issues a request using the current access token to check if it is still valid.
10041004 * If the request returns 200, no refresh happens, and we keep the token.
10051005 * If it returns 401, jsforce will request a new token and set it in the connection instance.
10061006 */
1007- public async refreshAuth ( ) : Promise < void > {
1008- this . logger . debug ( 'Refreshing auth for org.' ) ;
1009- const requestInfo : HttpRequest = {
1010- url : this . getConnection ( ) . baseUrl ( ) ,
1011- method : 'HEAD' ,
1012- } ;
10131007
1014- await this . getConnection ( ) . request ( requestInfo ) ;
1008+ public async refreshAuth ( ) : Promise < ReturnType < Connection [ 'refreshAuth' ] > > {
1009+ await this . getConnection ( ) . refreshAuth ( ) ;
10151010 }
10161011
10171012 /**
Original file line number Diff line number Diff line change @@ -945,10 +945,15 @@ describe('Org Tests', () => {
945945
946946 describe ( 'refresh auth' , ( ) => {
947947 let url : string ;
948+ type RequestInfo = { method : string } & AnyJson ;
949+
948950 beforeEach ( ( ) => {
949- $$ . fakeConnectionRequest = ( requestInfo : AnyJson ) : Promise < AnyJson > => {
950- url = ensureString ( ensureJsonMap ( requestInfo ) . url ) ;
951- return Promise . resolve ( { } ) ;
951+ $$ . fakeConnectionRequest = ( requestInfo : RequestInfo ) : Promise < AnyJson > => {
952+ if ( requestInfo . method === 'GET' ) {
953+ url = ensureString ( ensureJsonMap ( requestInfo ) . url ) ;
954+ return Promise . resolve ( { } ) ;
955+ }
956+ throw new Error ( 'refreshAuth should always a GET request to get the response body' ) ;
952957 } ;
953958 } ) ;
954959 it ( 'should request an refresh token' , async ( ) => {
You can’t perform that action at this time.
0 commit comments