Skip to content

Commit

Permalink
chore: refreshAuth methods do HEAD request
Browse files Browse the repository at this point in the history
jsforce only needs the response status code to refresh the session.
  • Loading branch information
cristiand391 committed Jan 16, 2025
1 parent fa7817a commit 1170cd7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2024, Salesforce.com, Inc.
Copyright (c) 2025, Salesforce.com, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
14 changes: 9 additions & 5 deletions src/org/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { asString, ensure, isString, JsonMap, Optional } from '@salesforce/ts-ty
import {
Connection as JSForceConnection,
ConnectionConfig,
HttpMethods,
HttpRequest,
QueryOptions,
QueryResult,
Expand Down Expand Up @@ -414,14 +413,19 @@ export class Connection<S extends Schema = Schema> extends JSForceConnection<S>
}

/**
* Executes a get request on the baseUrl to force an auth refresh
* Useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes
* Executes a HEAD request on the baseUrl to force an auth refresh.
* This is useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes.
*
* This method issues a request using the current access token to check if it is still valid.
* If the request returns 200, no refresh happens, and we keep the token.
* If it returns 401, jsforce will request a new token and set it in the connection instance.
*/

public async refreshAuth(): Promise<void> {
this.logger.debug('Refreshing auth for org.');
const requestInfo = {
const requestInfo: HttpRequest = {
url: this.baseUrl(),
method: 'GET' as HttpMethods,
method: 'HEAD',
};
await this.request(requestInfo);
}
Expand Down
9 changes: 7 additions & 2 deletions src/org/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,13 +792,18 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
}

/**
* Refreshes the auth for this org's instance by calling HTTP GET on the baseUrl of the connection object.
* Executes a HEAD request on the baseUrl to force an auth refresh.
* This is useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes.
*
* This method issues a request using the current access token to check if it is still valid.
* If the request returns 200, no refresh happens, and we keep the token.
* If it returns 401, jsforce will request a new token and set it in the connection instance.
*/
public async refreshAuth(): Promise<void> {
this.logger.debug('Refreshing auth for org.');
const requestInfo: HttpRequest = {
url: this.getConnection().baseUrl(),
method: 'GET',
method: 'HEAD',
};

await this.getConnection().request(requestInfo);
Expand Down

0 comments on commit 1170cd7

Please sign in to comment.