Forum Discussion
conseguir accesToken para power bi
Buenos dias estoy intentando conseguir el accesToken de Azure para power bi para poder ver los informes en mi pagina web
ademas de embeberlos
este es mi back
async create_acces_token(req, res) {
const group = process.env.group;
const idreport = process.env.idreport;
const authorityHostUrl = process.env.authorityHostUrl;
const tenant = process.env.tenant;
const authorityUrl = process.env.authorityUrl;
const resource = process.env.resource;
const clientID = process.env.clientID;
const clientSecret = process.env.valor;
const apiUrl = `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/token`;
const formData = new FormData();
formData.append('grant_type', 'client_credentials');
formData.append('client_secret', clientSecret);
formData.append('client_id', clientID);
formData.append('scope', 'https://analysis.windows.net/powerbi/api/.default');
const axiosConfig = {
headers: {
...formData.getHeaders()
},
};
axios.post(apiUrl, formData, axiosConfig)
.then(response => {
res.json({ status: true, acces_token: response.data.access_token,data:{group:group, idreport:idreport}})
})
.catch(error => {
res.json({ status: false })
console.error('Error:', error.message);
});
}
y este el front
async create_acces_token(req, res) {
const group = process.env.group;
const idreport = process.env.idreport;
const authorityHostUrl = process.env.authorityHostUrl;
const tenant = process.env.tenant;
const authorityUrl = process.env.authorityUrl;
const resource = process.env.resource;
const clientID = process.env.clientID;
const clientSecret = process.env.valor;
const apiUrl = `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/token`;
const formData = new FormData();
formData.append('grant_type', 'client_credentials');
formData.append('client_secret', clientSecret);
formData.append('client_id', clientID);
formData.append('scope', 'https://analysis.windows.net/powerbi/api/.default');
const axiosConfig = {
headers: {
...formData.getHeaders()
},
};
axios.post(apiUrl, formData, axiosConfig)
.then(response => {
res.json({ status: true, acces_token: response.data.access_token,data:{group:group, idreport:idreport}})
})
.catch(error => {
res.json({ status: false })
console.error('Error:', error.message);
});
}
este el error
Request failed with status code 403
Gracias de antemano un saludo
- Anonymous2 years ago
Hi GustavoMiranda,
As the document said, the 403 error means the server to indicate that access to the requested resource is forbidden. (this status code is triggered for various reasons and signifies that while the server understood the request, it refuses to grant access)
Have you checked the test account and permission setting to confirm it has enough permissions to invoke these rest API?
How to Get Your Question Answered Quickly
In addition, you can also take a look at the following link if helps:
Solved: REST API Get Access Token - Microsoft Fabric Community
Regards,
Xiaoxin Sheng
1 Reply
- AnonymousNot applicable
Hi GustavoMiranda,
As the document said, the 403 error means the server to indicate that access to the requested resource is forbidden. (this status code is triggered for various reasons and signifies that while the server understood the request, it refuses to grant access)
Have you checked the test account and permission setting to confirm it has enough permissions to invoke these rest API?
How to Get Your Question Answered Quickly
In addition, you can also take a look at the following link if helps:
Solved: REST API Get Access Token - Microsoft Fabric Community
Regards,
Xiaoxin Sheng