Basic oAuth for QBO BOD-266
This commit is contained in:
31
server/accounting/qbo/qbo-authorize.js
Normal file
31
server/accounting/qbo/qbo-authorize.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
});
|
||||
const OAuthClient = require("intuit-oauth");
|
||||
var Tokens = require("csrf");
|
||||
var tokens = new Tokens();
|
||||
const oauthClient = new OAuthClient({
|
||||
clientId: process.env.QB_ONLINE_CLIENT_ID,
|
||||
clientSecret: process.env.QB_ONLINE_SECRET,
|
||||
environment: "sandbox", //process.env.NODE_ENV === "production" ? "production" : "sandbox",
|
||||
redirectUri: process.env.QB_ONLINE_REDIRECT_URI,
|
||||
});
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
console.log("QBO Authorize Called");
|
||||
const { userId } = req.body;
|
||||
console.log("exports.default -> userId", userId);
|
||||
// AuthorizationUri
|
||||
|
||||
const authUri = oauthClient.authorizeUri({
|
||||
scope: [OAuthClient.scopes.Accounting, OAuthClient.scopes.OpenId],
|
||||
state: tokens.create(userId),
|
||||
}); // can be an array of multiple scopes ex : {scope:[OAuthClient.scopes.Accounting,OAuthClient.scopes.OpenId]}
|
||||
console.log("authUri", authUri);
|
||||
// Redirect the authUri
|
||||
res.send(authUri);
|
||||
};
|
||||
Reference in New Issue
Block a user