Skip to content

Instantly share code, notes, and snippets.

@mootrichard
Last active March 11, 2018 23:32
Show Gist options
  • Save mootrichard/e3a08fe3ac027f819c66e78ce9cc2a15 to your computer and use it in GitHub Desktop.
Save mootrichard/e3a08fe3ac027f819c66e78ce9cc2a15 to your computer and use it in GitHub Desktop.
Square Authorization Route
const CLIENT_ID = process.env.APPLICATION_ID;
const SECRET = process.env.SECRET;
function getState() {
return (crypto.randomBytes(32)).toString('base64');
}
router.get("/authorize", (req, res) => {
if(req.auth.isLoggedIn) {
res.redirect("/authorized");
} else {
const squareAuthURL = "https://connect.squareup.com/oauth2/authorize?";
req.auth.state = getState();
res.redirect(
squareAuthURL +
`client_id=${CLIENT_ID}&` +
`response_type=code&` +
`scope=MERCHANT_PROFILE_READ&` +
`session=false&` +
`locale=en-US&` +
`state=${req.auth.state}`
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment