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:
PHP Package Checklist The PHP Package Checklist is a project by Jonathan Reinink that is designed to help you go through all the steps to create a new PHP P… Read More
Install Spark in an Existing Laravel App With the alpha release of Laravel Spark, it includes an installer for scaffolding out everything for a new Laravel app but it left out the … Read More
Eloquence Package hits V2 Eloquence is a package to extend Laravel 5’s base Eloquent models and it has just hit version 2.Some of the features of the package include… Read More
WordPress and Laravel WordPress is one of the most popular open source applications and that means many people are comfortable using its admin to manage their site. T… Read More
Laravel Package for failed Queue Notifications The company Spatie released a new open source package to handle queue job failure notifications. When one fails it will send you an email with t… Read More
0 comments:
Post a Comment
Thanks