question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Integration with sfdx?

See original GitHub issue

After authenticating with an org via sfdx’s (which uses oauth under the hood), it stores the accessToken and other details in a json file in the ~/.sfdx folder.

Example:

{ orgId: '00Dd0000000cddqEAA',
  accessToken: 'aaa7d0647d....3f427',
  refreshToken: '9ca044f...99444886',
  instanceUrl: 'https://org.my.salesforce.com',
  loginUrl: 'https://login.salesforce.com',
  username: 'j...@salesforce.m',
  isDevHub: true }

If I use the accessToken and instanceUrl from that file:

const conn = new jsforce.Connection({instanceUrl, accessToken});

I get this error:

sf:INVALID_SESSION_ID: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session

Any ideas?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
douglascayerscommented, May 9, 2018

Rather than parse the ~/.sfdx folder, run theforce:org:display command with json output to obtain the access token.

sfdx force:org:display -u myorg --json
{
    "status":0,
    "result":{
        "password":"foo123",
        "username":"username@email.com",
        "devHubId":"devhub.username@email.com",
        "id":"00DR0000001oKnrMBE",
        "createdBy":"devhub.username@email.com",
        "createdDate":"2018-05-08T02:12:36.000+0000",
        "expirationDate":"2018-05-15",
        "status":"Active",
        "edition":"Developer",
        "orgName":"Company",
        "accessToken":"00DR...6unNVNRBWcP2i",
        "instanceUrl":"https://<instance>.my.salesforce.com",
        "clientId":"SalesforceDevelopmentExperience",
        "alias":"myorg"
    }
}
1reaction
douglascayerscommented, Oct 25, 2018

My guess is that the force:org:display command is not refreshing the token before showing it, perhaps displaying the last obtained value which may or may not still be valid. Or, maybe the scratch org has expired and the token is literally no longer valid.

You might try running the force:limits:api:display command first which likely will require the access token to be refreshed because the CLI has to make a REST API call and would auto-renew the token if necessary.

https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_limits.htm#cli_reference_api_display

Read more comments on GitHub >

github_iconTop Results From Across the Web

Continuous Integration | Salesforce DX Developer Guide
Continuous integration (CI) is a software development practice in which developers regularly integrate their code changes into a source code repository.
Read more >
SFDX Continuous Integration | Tigerface Systems
In this post we will setup a CI (continuous integration) workflow that automatically runs our Apex and LWC unit tests on each code...
Read more >
Salesforce DX Continuous Integration | by Ariel Dornelles
Hi everyone, I'm writing this post intending to help Salesforce developers who are starting their studies about Salesforce DX and want to ...
Read more >
CI and Delivery Using Salesforce Developer Experience
Salesforce Developer Experience (SFDX) helps build a better continuous integration (CI) and delivery system with a simplified version ...
Read more >
Salesforce deployment using SFDX CLI, Jenkins and GitHub
To start with basic I created Dev Org using Visual Studio Code and committed same to GitHub. Integrated SFDX CLI with Jenkins and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found