-
Notifications
You must be signed in to change notification settings - Fork 78
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
External Credential using OAuth 2.0 with JWT Bearer Flow deployed to Scratch Org does not work #3025
Comments
Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support. |
Hey @jclark-dot-org - that's quite a complex setup and a lot to dig through... however, I'm not sure Have you seen the documentation mentioning a transition to Named Credentials Schema? furthermore, there's additional setup guidance here and here |
@WillieRuemmele I believe I am using Named Credentials Schema. This isn't the legacy Named Credentials; it uses an External Credential, Named Principal, and Named Credentials, as outlined in my ticket. They are easily retrieved and deployed; the only issue seems to be the Certificate, which I thought might be tied to the Identity Provider issue. However, As another test, I created a new scratch, manually created a self-signed cert and enabled Identity Provider, and then pushed my google cert; it still turns into a Salesforce cert ( |
I guess I'm not sure if this is a CLI issue, or a server-side issue
can you set the if it's a google cert, something on the server is changing it. if it's a salesforce cert, then the bug lies in the CLI's domain, and then we can fix it. |
@WillieRuemmele After doing some more research: The JKS file used to import the keys includes both a private key and the auth provider certificate for the key. The certificate ( I'm a bit confused by how the imported cert appears in the org, but that's not a CLI issue, and now I don't think any of this this is a CLI issue, at least as I've written it up, so I'm closing this ticket. I do think there needs to be some way to programmatically/declaratively import keys into a new scratch org, but I'll do some more research and open a new ticket if it makes sense. Thanks for your time. |
Closing; see previous comment. |
Summary
I have an
sf
project that integrates with the Google API using Named Credentials, which in turn use an External Credential which authenticates as a Google Service Account using OAuth2.0 with JWT Bearer Flow. It works in the original scratch, and I can configure it manually in another scratch org, but I cannot successfully build a working new scratch withsf project deploy start
. The source deploys, but the integration does not work because the certificate is not imported correctly ("Unable to complete the JWT token exchange. Error: invalid_grant. Error description: Invalid JWT Signature.")Steps To Reproduce
I cannot provide a repository, because I would need to expose my Google certificate.
Here are the basic steps to setup the Named Credential/External Credential/etc. I can provide full details with links, etc, but it's not required to understand the issue. Mostly I have followed the steps in this Salesforce StackExchange answer. See "Additional Information" below for a concise explanation of the issue.
keytool
to convert the p12 file to a JKS file."https://oauth2.googleapis.com/token". Add a claim, name it "scope", and set it, including one or more Google API scopes; I am using "openid email https://www.googleapis.com/auth/drive".
That's all the manual config, and any apex code that uses the Named Credential will work. As to the issue:
sf project retrieve start
. This should include certs for both the IDP cert from step 4 and the imported Google cert from step 5, the external credential from step 6 and the named credential from step7, as well assettings/Security.settings-meta.xml
. I'm pulling Security Settings because it showed as a modified file, and I assumed that was to reflect the changes from `Enable Identity Provider" in step 4 above. As you will see below, that seems to be wrong.sf project deploy start
. This will succeed.CN=privatekey
and "O=Salesforce.com" among other values; compare to step 4 above. This is not the google key imported in the first scratch org; it appears to be a Salesforce-self signed cert. See screenshots below.Expected result
The correct Google Certificate should have been created in the new scratch org. Identity Provider should already be enabled.
Actual result
A cert with the same name is created, but it is a different cert, and appears to be a Salesforce self-signed cert, not the Google Service Account key. Identity Provider is not enabled.
Additional information
The issue is that a certificate imported into salesforce in one org, retrieved via
sf project retrieve
, and pushed to another org, is not created correctly in the second org. This may be a side effect of the fact that enabling an Identity Provider in one scratch doesn't seem to be transferred to another scratch.As an additional test, I ensured that my project was completely in sync with the second scratch org (
sf project retrieve preview
showed no differences), then Enabled Identity Provider, then checked org state withsf project retrieve preview
again; it showed no differences.Here's what the import key looks like in the original scratch org:
And here's what it looks like after being deployed to a new scratch org:
System Information
Using zsh on Mac OS 14.6.1
sf cli info:
The text was updated successfully, but these errors were encountered: