Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refresh access token before issuing request #62

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

cristiand391
Copy link
Member

@cristiand391 cristiand391 commented Jan 15, 2025

What does this PR do?

DEPENDS ON: forcedotcom/sfdx-core#1163

Makes api request rest the access token before setting it as the bearer token for the request.

Repro

  1. create a scratch org
  2. get current access token and expire it
export SF_AT=$(sf org display --json | jq -r .result.accessToken) &&
echo "token=$SF_AT&token_type_hint=access_token" > token.txt &&
curl "https://customer-customization-3903-dev-ed.scratch.my.salesforce.com/services/oauth2/revoke" -d "@token.txt" -H 'Content-Type: application/x-www-form-urlencoded' -i

you should get HTTP status code 200 to confirm it was expired:

HTTP/2 200
...
  1. run api request rest, see it fail b/c it used the expired access token:
➜  plugin-api git:(cd/refresh-token) ✗ sf api request rest services/data/v62.0/limits
Warning: This command is currently in beta. Any aspect of this command can change without advanced notice. Don't use beta commands in your scripts.
[
  {
    "message": "Session expired or invalid",
    "errorCode": "INVALID_SESSION_ID"
  }
]

See testing steps here:
forcedotcom/sfdx-core#1163

What issues does this PR fix or reference?

forcedotcom/cli#3176
@W-17605467@

@WillieRuemmele
Copy link
Contributor

QA Notes


with core PR linked

➜  dreamhouse-agents git:(main) ✗  hub:(GLOBAL - DevHub) scratch:(test-2j5f2xi8t2ne@example.com)
 ➜  sf api request rest services/data/v62.0/limits
Warning: This command is currently in beta. Any aspect of this command can change without advanced notice. Don't use beta commands in your scripts.
[
  {
    "message": "Session expired or invalid",
    "errorCode": "INVALID_SESSION_ID"
  }
]
➜  dreamhouse-agents git:(main) ✗  hub:(GLOBAL - DevHub) scratch:(test-2j5f2xi8t2ne@example.com)
 ➜  ../../oss/plugin-api/bin/run.js api request rest services/data/v62.0/limits
Warning: This command is currently in beta. Any aspect of this command can change without advanced notice. Don't use beta commands in your scripts.
{
  "AnalyticsExternalDataSizeMB": {
    "Max": 40960,
    "Remaining": 40960
  },

✅ : when running the linked command directly after expiring AT, it refreshed it, and worked

@WillieRuemmele WillieRuemmele merged commit a45f2f5 into main Jan 17, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants