Repository navigation
Closed
Description
Summary
When using sf org create user to create a user in a scratch org command returns error when using JWT authentication even if user is successfully created.
Steps To Reproduce
- Auth using
sf org login jwt
sf org login jwt `
--username $(orgUsername) `
--jwt-key-file $(jwtKeyFile) `
--client-id $(clientId) `
--alias scratchOrgAlias `
--instance-url $(orgLoginUrl)- Create user
sf org create user --target-org scratchOrgAlias --definition-file $def --set-unique-usernameExpected result
- If user is created command should exit normally
Actual result
- User is successfully created in org
- CLI returns below
Errors encountered:
user hasn't approved this consumer
user hasn't approved this consumer
user hasn't approved this consumer
user hasn't approved this consumer
user hasn't approved this consumer
at SfError.wrap (/home/vsts/.config/yarn/global/node_modules/@salesforce/core/lib/sfError.js:79:20)
at catchCreateUser (/home/vsts/.config/yarn/global/node_modules/@salesforce/plugin-user/lib/commands/org/create/user.js:255:30)
at getNewUserAuthInfo (/home/vsts/.config/yarn/global/node_modules/@salesforce/plugin-user/lib/commands/org/create/user.js:238:16)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async CreateUserCommand.run (/home/vsts/.config/yarn/global/node_modules/@salesforce/plugin-user/lib/commands/org/create/user.js:43:33)
at async CreateUserCommand._run (/home/vsts/.config/yarn/global/node_modules/@salesforce/sf-plugins-core/node_modules/@oclif/core/lib/command.js:117:22)
at async Config.runCommand (/home/vsts/.config/yarn/global/node_modules/@salesforce/cli/node_modules/@oclif/core/lib/config/config.js:400:25)
at async run (/home/vsts/.config/yarn/global/node_modules/@salesforce/cli/node_modules/@oclif/core/lib/main.js:85:16); exitCode=1; warnings=System.Object[]}
@{code=1; context=CreateUserCommand; commandName=CreateUserCommand; message=Error authenticating with JWT.
System Information
Ubuntu - pwsh
{
"architecture": "linux-x64",
"cliVersion": "@salesforce/cli/2.17.14",
"nodeVersion": "node-v18.18.2",
"osVersion": "Linux 6.2.0-1015-azure",
"rootPath": "/home/vsts/.config/yarn/global/node_modules/@salesforce/cli",
"shell": "bash",
"pluginVersions": [
"@oclif/plugin-autocomplete 3.0.1 (core)",
"@oclif/plugin-commands 3.0.6 (core)",
"@oclif/plugin-help 6.0.5 (core)",
"@oclif/plugin-not-found 3.0.3 (core)",
"@oclif/plugin-plugins 4.1.7 (core)",
"@oclif/plugin-search 1.0.6 (core)",
"@oclif/plugin-update 4.1.3 (core)",
"@oclif/plugin-version 2.0.6 (core)",
"@oclif/plugin-warn-if-update-available 3.0.2 (core)",
"@oclif/plugin-which 3.0.8 (core)",
"@salesforce/cli 2.17.14 (core)",
"apex 2.3.20 (core)",
"auth 2.8.26 (core)",
"data 2.6.3 (core)",
"deploy-retrieve 1.20.0 (core)",
"info 3.0.1 (core)",
"limits 3.0.1 (core)",
"login 2.0.1 (core)",
"marketplace 1.0.2 (core)",
"org 2.11.8 (core)",
"schema 3.0.1 (core)",
"settings 2.0.2 (core)",
"sobject 0.2.15 (core)",
"source 2.11.0 (core)",
"telemetry 3.1.0 (core)",
"templates 55.5.18 (core)",
"trust 3.0.2 (core)",
"user 2.3.42 (core)"
]
}Additional information
Reacted by akalatsky
Activity
github-actions commentedon Nov 17, 2023
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.
mshanemc commentedon Nov 17, 2023
After the user is created, the CLI is going to try to auth the new user with the same JWT connected app. Can you confirm that the created user will have access to do that (the Connected App allows their assigned Profile?)
nwcm commentedon Nov 20, 2023
In this case probably not, the scratch org is created with a system admin user, which is the authentication used to run the command.
Trying to create standard users which we don't need the cli to auth for nor do they need access to the connected app.
There is no connected app in the scratch org for this, it is the connected app from the Partner Business Org. I assume this may only be available to system admins scratch orgs not standard users
mshanemc commentedon Nov 21, 2023
the purpose of
org create useris to create users that are auth'd via the CLI so you can do CLI stuff as that user. Auth is built into the process. I understand why that's confusing and maybe we could fix it.Scratch org creation replicates the ConnectedApp from the DevHub into the scratch org.
If you just want to create a user as a part of a script, I'd suggest either
sf data create recordand pass the fields it needssf apex run -f <your file>nwcm commentedon Nov 22, 2023
@mshanemc
I understand, however I think there is some odd behavior in the
org create usercommand.If I create a scratch org, and then run
org create userin a ci/cd context for using the auth, even with system admin that user returns the error. So, the propose of creating a user and switching authentication context for commands isn't working for me using jwt.I think this command doesn't support the
jwtauthentication method. There is nothing additional in the documentation for using jwt. As you would have to create the user, grant them access to the connected app, then authenticate?https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_create_user_unified
https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_users.htm
The reason using
org create useris more useful is being able to define the user definition with all user information and permissionset.nwcm commentedon Nov 22, 2023
Additionally, as we need this users authentication details, as the
org user createfails we are unable to useorg password generatefor this user.https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_auth_connected_app.htm
mshanemc commentedon Nov 22, 2023
@nwcm it works if the user being created has access to the ConnectedApp (ex: SystemAdmin or some other profile is allowed for the ConnectedApp, and the user being created is assigned that Profile). I'd guess that if you created a user that gets assigned the SystemAdmin profile it'd auth correctly.
That's the trick
If not, please let me know what command you're using and screenshot your ConnectedApp settings (permissionSets/Profiles) to make sure you've got everything correct.
You definitely can't set a password for a user that the CLI is not authenticated with. (That API/permission is called
selfSetPassword, meaning an admin can't do it for other users, on for themselves). That's why theorg password generateuses--on-behalf-ofas a user that the CLI has auth'd and not just anybody in the org.[there is an API to initiate the password reset process for a user that's not yourself, but they get an email link, etc to do the actual process]
nwcm commentedon Nov 22, 2023
Hey @mshanemc
Yeah even with
System Administratorprofile configured it still fails to authenticate as the new userI also tried removing the permissionset and only having the profile defined but it still fails.
I changed IP restrictions to lax and the same, i've run out of ideas. I also found https://salesforce.stackexchange.com/questions/409375/do-scratch-orgs-have-weird-behaviors-with-connected-apps-being-given-invalid-g
I'm not sure how to confirm the connected app is cloned into the scratch org
ns-091 commentedon Nov 22, 2023
@mshanemc this problem looks to be directly related to this known issue as the steps to reproduce mirror ours ( https://issues.salesforce.com/issue/a028c00000j5kSUAAY/an-error-message-returned-when-running-forceusercreate-for-scratch-org-of-hyperforce-using-oauth-20-jwt-bearer-flow )
However the issue is marked as working as intended with no reference to a document explaining why it's expected for this not to work.
mshanemc commentedon Nov 22, 2023
Ahh, that was the missing step. I should have put together that you're likely on hyperforce trying this, had forgotten about that "feature".
github-actions commentedon Nov 22, 2023
Thank you for filing this feature request. We appreciate your feedback and will review the feature at our next grooming or sprint planning session. We prioritize feature requests with more upvotes and comments.
git2gus commentedon Nov 22, 2023
This issue has been linked to a new work item: W-14542428
mshanemc commentedon Nov 22, 2023
I'm going to put an error message in there so people know why this isn't working. Marking that as a feature.
nwcm commentedon Nov 22, 2023
Right, so if i'm understanding correctly. Any CI/CD using hyperforce orgs can only ever use the original user created with the scratch org.
Probably also why the scratch org cannot authenticate new users on API only profile
mshanemc commentedon Nov 22, 2023
That's overly broad...you could use sfdx-url auth instead of JWT. Those work fine on hyperforce.
I think there's also a really complex path to
org create usernwcm commentedon Nov 22, 2023
@mshanemc
I might be missing something, but sfdx-url seems to be limited to web auth flows. The only solution may be the creation of a connected app in every scratch org.
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_org_commands_unified.htm#cli_reference_org_login_sfdx-url_unified
dshelgunov commentedon Dec 7, 2023
Hello, any update for this issue? Until now every workaround involves manual authentication which cannot be automated. So this makes all our scratch organization tests creating users fail.
mshanemc commentedon Dec 7, 2023
It's never going to work on hyperforce wth JWT (that's a change in the underlying user replication infrastructure that the CLI can't do anything about). We're changing the command to throw an error before it even tries when it knows you're both JWT and hyperforce.
If you need to automate this kind of thing, you'll need to do a non-JWT auth (ex: use sfdx-url). That's how we do our automated tests.
dshelgunov commentedon Dec 7, 2023
Okay got it working. @mshanemc I think I have missed or misunderstood the proposed solutions in the different threads.
Here is a step-by-step of what worked for me to move from JWT to sfdx-url authentication:
sf org login webto link back your dev-hub account previously using JWT.sf org display --target-org TestOrg1 --verbosesf org login sfdx-urlOnce these steps are done, creating scratch orgs and users will work. If you need to re-authenticate to existing scratch orgs or users, make sure to persist their unique sfdx auth urls using
sf org display --target-org TestOrgOrUser --verbosewhen initially creating these.So leaving these here and hope that helps someone else 😄
jshackell-sfdc commentedon Dec 13, 2023
This issue is addressed in 2.21.7 (Dec 13, 2023). Thank you!