In this blog I am going to discuss on how we can generate Authentication token for WebApi calls in PowerApps portals.
This is the second blog in the series. If you have come to this blog directly, I strongly suggest you go to the first blog of the series to get more context.
So we are at the first step of performing our WebApi operations. And we are going to communicate to Dynamics 365/ CDS environment from Portals. Now portal and Dynamics 365 or CDS environment are two different applications. And it is quite obvious that to perform operations on CDS environment from portals using WebApi, we would need a bearer token.
It’s actually very easy. Dynamics 365/ PowerApps portals have inbuilt API’s to generate token required for authentication with CDS. Below is the sample code to do the same.
shell.getTokenDeferred().done(function(token){
console.log("Authentication token: ", token);
});
You have generated the authentication token successfully. Now you are now ready to perform WebApi operations using this authentication token. And this authentication token need to be included with every request as a request header.
The details of the request header and how to include for requests will be discussed in the next blog. In the next blog we will use this Authentication token to accomplish create/ update/ delete operations in Dynamics 365/ CDS from PowerApps portals. And all with simple XmlHttpRequests and not some fancy javascript constructs.
Hope this helps!
Debajit Dutta
(Business Solutions MVP)
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.