Hello, I'm Kim Woo Chang.
If I attach Excel files in the current canvas app, I want to create a PCF that CRUDs data into the Sharepoint List.
However, there is an error when calling Rest Api inside the PCF, so it cannot be used.
Neither my Azure functions nor graph api were available.
Can I get an idea of what to do?
Cross-Origin Resource Sharing error
Below is an example of the source code you tried.
private async getAccessToken(): Promise<string> {
// 여기에 로직을 구현하여 액세스 토큰을 반환합니다.
const tokenEndpoint = "https://login.microsoftonline.com/tenentid/oauth2/v2.0/token"; // 이후 수정 필요
const clientId = "";
const clientSecret = "";
const grantType = "client_credentials";
const scope = "https://graph.microsoft.com/.default";
const params = new URLSearchParams();
params.append("grant_type", grantType);
params.append("client_id", clientId);
params.append("client_secret", clientSecret);
params.append("scope", scope);
let accessToken = "";
console.log("fetch시작");
await fetch(tokenEndpoint, {
method: "POST",
mode: 'no-cors',
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: params
})
.then(response => response.json())
.then(data => {
accessToken = data.access_token;
})
.catch(error => console.error("Error:", error));
console.log("accessToken 가져옴?");
console.log(accessToken);
return accessToken;
}