I have an app where im trying to send a generated pdf to get a signature. Pretty straightforward.
I got the authentication working in postman, but when I try it in code, I get this error:
Access to fetch at '
https://account-d.docusign.com/oauth/token' from origin '
http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I can retrieve the oauth code with this:
if (router.asPath !== router.route) {
setOAuthCode(new URLSearchParams(window.location.search).get("code"));
}
but in a seperate use effect, i try to submit this oAuth code, it falls appart:
useEffect(() => {
const getAuthToken = async () => {
const tokenUrl = "
https://account-d.docusign.com/oauth/token";
/>
const encodedSecret = btoa(
`${process.env.NEXT_PUBLIC_DOCUSIGN_INTEGRATION_KEY}:${process.env.NEXT_PUBLIC_DOCUSIGN_CLIENT_SECRET}`
);
const headers = {
"Authorization": `Basic ${encodedSecret}`,
"Content-Type": "application/x-www-form-urlencoded",
};
const body = new URLSearchParams({
grant_type: "authorization_code",
code: oAuthCode,
});
const response = await fetch(tokenUrl, {
method: "POST",
headers: headers,
body: body,
});
if (!response.ok) {
throw new Error(
`Failed to get access token: ${response.status} ${response.statusText}`
);
}
const data = await response.json();
setAuthToken(data.access_token);
};
getAuthToken();
}, [oAuthCode]);
Any kung fu would be greatfully accepted
How to resolve a Cors error when trying to get an authentication token using authorisation code grant in Next.js
Programing Coderfunda
July 08, 2024
No comments
Related Posts:
Magento 2 Module Development Magento 2 Module DevelopmentIn this educational activity, we have made absolute "News" module in Magento 2. You can learn module improvement pro… Read More
6 Steps to Install Magento 2.4.2 on XAMPP Windows Using Install Magento 2.4 in Windows 10 using composer and command line with ElasticsearchIn this post we will learn, download the Magento 2.4&nb… Read More
Create Tree View and Get category and subcategory in php Create Tree View and Get category and subcategory in phpCreate categories table CREATE TABLE `categories` ( `id` int(11) NOT NULL, `parent_id` i… Read More
How to show collection on frontend with pagination in Magento 2 How to show collection on frontend with pagination in Magento 2Create routes.xmlRsgitech\News\etc\frontend\routes.xml<?xml version="1.0"?>… Read More
How to get single record from collection in Magento 2 How to get single record from collection in Magento 2Create View.php Controller ActionRsgitech\News\Controller\Index\View.php<?php namespace … Read More
0 comments:
Post a Comment
Thanks