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:
How to add Menus in Wordpress To add menus in Wordpress please follow the below step: Step 1 – Select Appearance → Menus from the dashboard. Then you find a pag… Read More
Wordpress Widgets With Screenshot Wordpress widget is used to add content and features. It can be easily dragged and dropped in widget area. The features are different in different t… Read More
Wordpress links With Example Link is a connection from one page to another page. Adding links to your pages or blog posts help you to connect to other pages. How to add links i… Read More
Wordpress Theme Management Theme help to make your website look great. From here you can install, delete, update and activate themes. In this chapter we discusses how to insta… Read More
Wordpress Plugins With Screenshot Wordpress plugin is nothing but is a program that is written in php scripting language. It is used to extend the functionality and features of our w… Read More
0 comments:
Post a Comment
Thanks