When an authentication provider authenticates via provider form, the form submit handlers take care of two things:
1) fetching a valid auth (and refresh) token from Salesforce
2) using that token to fetch a Salesforce identity, which defines the API endpoints used to access various APIs used by this module.
This works fine when authenticating on the auth provider form.
But, when you need to revoke or reset a token (e.g. after syncing environments from prod to sandbox), the identity is never reset.
Auth providers should refresh identity every time an access token is refreshed or reset, not just in the form submit handlers.
| Comment | File | Size | Author |
|---|
Issue fork salesforce-3102133
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
darksnowThis patch adds three commands while allow the user to list, revoke and crucially, refresh authentication tokens from the command line.
In my use case I've edited the Salesforce YAML files to remove any authentication credentials and then changes the settings file to set this config entries from environment variables. This leaves the settings form in an invalid state so I can't use the UI to get a token since form validation fails.
The revoke and refresh commands themselves can take the machine name of the authentication provider as an argument. If no argument is given they both find the default provider and act on that.
Comment #3
darksnowComment #4
aaronbaumanInteresting idea, thank you for the patch.
Fetching the auth provider is a tad overcomplicated in both
listAuthProvidersandrefreshToken:In each case, simplify this with:
While I appreciate these additional commands, how do these help address your original concern?
Are you envisioning additional commands to perform the initial oauth handshake as well?
Comment #5
aaronbaumanChanged to "needs work" to address feedback in prior comment.
Comment #6
darksnowThanks, that's much neater :)
Comment #8
aaronbaumanThis is in.
Resetting to "active", since these commands don't actually provide an alternative to entering credentials via admin page.
Comment #9
darksnowThanks Aaron.
Now you've set this back to active, what more would you like me to add?
The original idea was that you can now add credentials to your settings.php file and this command would then pick them up, this seems like an alternative to the settings form.
Comment #10
aaronbaumanThis doesn't solve the problem of initial authentication - you still need to enter your creds to the settings form tologin to salesforce, complete the OAuth handshake, and generate the initial access and refresh tokens.
Unless you have another way to get those?
Comment #11
darksnowOK. I see what you mean now and you're partially correct.
This code was added to allow for an automated deployment without including any private data in any exported code. So, on my dev machine I did what you described and added my full details to the form and got the token. This was just to allow me to then export the configuration to YAML. I edited the YAML files to remove the private data, so my consumer key in the YAML file is
dummy_keyfor example.I then reimported the config. Convoluted perhaps but it allows me to protect the key, user and URL by removing them from the config before I commit to git. This of course now means the form will not submit since the data in there is invalid.
But, I then add the following to
settings.phpI could also replace the PEM file location, for example, depending on my environment.
Now, having done that, the form will still not work as it shows the contents of the config files, not the running settings. It's not affected by the $config changes above. The new command however, can get at these new config details and will run correctly.
So, in this way I can add dummy, invalid data to the YAML files and safely commit them to git, then have my new command pick up the correct config from the running environment and allow a deployment script to get the required access token securely.
It is a little convoluted since the token is generated in form validation, so I can't add incorrect keys to the form but I protecting those keys is exactly why I created this command.
I hope that clarifies my use case.
Comment #12
Ali_KC commentedHello,
That's still an issue. The Salesforce(SF) Identity wont change after overriding it the settings.php file which result an issue with SF connection. I am using JWT too.
Comment #13
aaronbaumanI have run into this recently as well.
The identity is only refreshed when re-saving the Auth Config form.
This is a problem when revoking an access token via drush or otherwise.
Identity should be refreshed whenever access token is refreshed or regenerated.
This issue persists into 5.0.x
Comment #14
bob.hinrichs commentedhave encountered this bug, and am following, thank you much
Comment #15
aaronbaumanUpdated IS
Comment #16
aaronbaumanComment #20
aaronbaumanOK, this fix is merged into 5.0.x and opened a new MR for 4.x
https://git.drupalcode.org/project/salesforce/-/merge_requests/19
also available as a patch: https://git.drupalcode.org/project/salesforce/-/merge_requests/19.patch
Comment #21
dswier commentedThanks for the patch. I tried it on 8.x-4.x-dev, and it works for me. With the patch, I am seeing the identity get refreshed whenever the token is refreshed.
Comment #23
aaronbaumanCommitted, thanks all!