31 lines
893 B
JavaScript
31 lines
893 B
JavaScript
const path = require("path");
|
|
require("dotenv").config({
|
|
path: path.resolve(
|
|
process.cwd(),
|
|
`.env.${process.env.NODE_ENV || "development"}`
|
|
),
|
|
});
|
|
const OAuthClient = require("intuit-oauth");
|
|
|
|
const oauthClient = new OAuthClient({
|
|
clientId: process.env.QBO_CLIENT_ID,
|
|
clientSecret: process.env.QBO_SECRET,
|
|
environment: process.env.NODE_ENV === "production" ? "production" : "sandbox",
|
|
redirectUri: process.env.QBO_REDIRECT_URI,
|
|
});
|
|
|
|
exports.default = async (req, res) => {
|
|
try {
|
|
const authUri = oauthClient.authorizeUri({
|
|
scope: [OAuthClient.scopes.Accounting, OAuthClient.scopes.OpenId],
|
|
state: req.user.uid,
|
|
}); // can be an array of multiple scopes ex : {scope:[OAuthClient.scopes.Accounting,OAuthClient.scopes.OpenId]}
|
|
// Redirect the authUri
|
|
res.send(authUri);
|
|
} catch (error) {
|
|
console.log(error);
|
|
res.sendStatus(500);
|
|
}
|
|
};
|
|
|