Closed mrcampbell closed 2 years ago
Your code looks correct, maybe it's an issue with the strategy code. Did you try this one: https://www.npmjs.com/package/passport-salesforce-oauth2 instead?
Thank you for the recommendation! Let me try that one out right now. Since this doesn't seem to be blitz related, I'll close this issue.
Ok! Feel free to reopen if the issue is on the Blitz side.
I still couldn't find what the issue was. I went so far as to copy the passport implementation into my own project, importing that rather than the npm package, and stepping through it. It indeed was being called in all the right ways, but for whatever reason, the verify
function wasn't being called. In an effort to speed things up, I did this, which works great for now!
(Sharing for posterity, just in case anyone else needs this)
// <project name>/app/api/auth/salesforce/callback.ts
import { BlitzApiRequest, BlitzApiResponse, getSession, Routes } from "blitz"
import { Connection, IdentityInfo, UserInfo } from "jsforce"
const handler = async (req: BlitzApiRequest, res: BlitzApiResponse) => {
var conn = new Connection({
clientId: process.env.SALESFORCE_KEY,
clientSecret: process.env.SALESFORCE_SECRET,
redirectUri: process.env.SALESFORCE_REDIRECT_URL,
instanceUrl: process.env.SALESFORCE_INSTANCE_URL,
})
// @ts-ignore
const code: string | undefined = req.query.code
// todo: handle, throw, etc
if (!code) {
res.statusCode = 500
res.setHeader("Content-Type", "application/json")
res.end(JSON.stringify({ name: "Code not found" }))
return
}
await conn.authorize(code)
.then((userInfo: UserInfo) => {
console.log(userInfo)
})
// do stuff with the userInfo, or call identity for more info,
// random example below
await conn.identity()
.then((res: IdentityInfo) => {
console.log("user ID: " + res.user_id);
console.log("organization ID: " + res.organization_id);
console.log("username: " + res.username);
console.log("display name: " + res.display_name);
});
// then redirect to wherever!
res.redirect('<route name>')
}
export default handler
What is the problem?
I've tried using
passport-forcedotcom
andpassport-salesforce
, and although I get a successful authorization, my verify callback isn't being called, and so I'm not able to use the data being passed back from the OAuth Provider.Is there something wrong with my code?
Paste all your error logs here:
Paste all relevant code snippets here:
What are detailed steps to reproduce this?
.env
vars (I've confirmed they're correct) and Salesforce's Connected App is configured correctly.http://localhost:3000/api/auth/salesforce
to Log In With Salesforceverify
callback being calledRun
blitz -v
and paste the output here:Please include below any other applicable logs and screenshots that show your problem:
No response