-
Notifications
You must be signed in to change notification settings - Fork 10
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
OAuth2
support in salesforce
#470
Conversation
oauth2
support in salesforce
@@ -55,7 +55,6 @@ | |||
"required": [ | |||
"loginUrl", | |||
"username", | |||
"password", | |||
"securityToken" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtuchi , is securityToken
not required anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taylordowns2000 according to jsforce, securityToken
is optional - https://jsforce.github.io/document/#username-and-password-login
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah wow. @aleksa-krolls , can you confirm that we don't need users to provide their security token when creating a new Salesforce credential? (is this an admin setting in a client's salesforce system? something like, "require security token for API access"?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most salesforce instance are configured to require securityToken
but if a client have a salesforce instance that does not require securityToken
then the job should pass.
The change i introduced also helps with credential creation on lighting which make the Security Token
input optional
packages/salesforce/src/Adaptor.js
Outdated
function createConnection(state) { | ||
const { loginUrl, apiVersion } = state.configuration; | ||
async function createBasicAuthConnection(state) { | ||
console.log('Attempting to connect with Basic Auth'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we log anywhere when the connection is successful?
I would much prefer to say:
Connected to salesforce as ${user}
Or
Failed to connected to salesforce as ${user}
Ie, print the result, not the process.
When we say "Attempting to..." it sort of shows a lack of confidence on our part, and when there's no log to follow it up it's gonna look pretty flaky.
For something routine, like logging in, we should be super confident in our logging. And when something goes wrong we should be super clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree on with the Connected to salesforce as ${username}
but on Failure i don't think we should log Failed to connect as ${username}
because this suggest that the username is wrong while it could be a number of reasons.
I would suggest we leave the error message that comes from salesforce which looks like this
INVALID_LOGIN: Invalid username, password, security token; or user locked out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtuchi , we added the username there (if i'm remembering this correctly) because it's incredibly helpful for the openfn end-user (the salesforce admin) to know which SF user they have to debug! users do get locked out, tokens become invalid, etc., etc.
printing the username is great for the salesforce admin. i don't think it will make them think that the username is wrong, i think it will help them figure out whether the password, token, or user status in salesforce is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that error implies that username is the fault. I agree with taylor that it's a useful bit of information to report.
I also agree that the original salesforce message is fine.
We can do both!
console.error(`Failed to connected to salesforce as ${user}`)
console.error(e.message) // or whatever
Actually, if we we throw the error, I think the runtime should report it (and if it doesn't, that's something I need to fix!)
console.error(`Failed to connected to salesforce as ${user}`)
throw e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay sounds good 👍🏽 , I will use this 👇🏽
console.error(`Failed to connected to salesforce as ${user}`)
throw e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hrmmm, i think we're not supposed to use console.error
, right? isn't it a different stream and won't it cause timing/printout issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taylordowns2000 I was going to say: console.error
should be fine - we redirect it to stdout anyway.
... but then I remembered that this doesn't use our logger, so yes it will go to a different stream and cause timing problems.
I don't think that's the fault of the adaptor though. Let me just dig into something here.
packages/salesforce/src/Adaptor.js
Outdated
accessToken: access_token, | ||
}); | ||
|
||
const connection = new jsforce.Connection(connectionOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need to do any sort of login
here?
The connection is synchronous, how do we know we're actually connected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No login there, It's a different strategy based on auth type,
So for basic-auth you will setup the connection then do connection.login(connectionOptions)
. And for accessToken auth, getConnection(state, connOpts)
will have the connection with session type oauth
For Basic Auth - https://jsforce.github.io/document/#username-and-password-login
For OAuth - https://jsforce.github.io/document/#access-token
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved subject to something in console.error
that I just want to look into.
I don't have a quick solution to the console.error thing. For the moment I've just renamed it to console.log. |
Summary
Add support for
OAuth2
in salesforce adaptorDetails
Improved the
createConnection
function to handle bothaccessToken
connection and Basic Auth connection. I have created two functions [createBasicAuthConnection
andcreateAccessTokenConnection
] that gets called increateConnection
depending on configuration-schema. I have also created another configuration-schema forOAuth
which requiresother_params.instance_url
andaccess_token
.Also in
configuration-schema
I have removed thesecurityToken
fromrequired
property since it's an optional valueIssues #410 #423
Review Checklist
Before merging, the reviewer should check the following items:
dev only changes don't need a changeset.