If you need to call external APIs using JavaScript from Power Pages, you may want to secure the calls to avoid exposing information or application hacking, as all the calls are made from client side.
Power Pages sites can have OAuth 2.0 implicit grant flow enabled, so you can obtain an authentication token that has your Portal as the issuer, and you can use this token to do authenticated calls to external APIs.
This post is a quick overview and summary of useful posts in the subject, as there are some good content around, I thought it would be useful to collate the links in a single place.
This Microsoft tutorial explains how to enable the OAuth 2.0 implicit flow in your site:
Use OAuth 2.0 implicit grant flow within your Power Pages site
Use the token in JavaScript
After enabling OAuth 2.0 implicit flow, you can obtain a token by calling the following endpoint and then use it to call the authenticated API:
<portal_url>/_services/auth/token
Sample…
Source link
More About This Author
-
SharePoint and Office 365 Consultant/Developer always trying to get the best from Microsoft stack (Microsoft 365/Azure/Power Platform and related stuff).
Living in Ireland since 2018, I had previously worked in Brazil as a consultant/developer for Office 365, SharePoint and related technologies for almost 10 years.
Array
- Modern Workplace13 April 2024Power Pages and Cloud Flows – Validate user against Dataverse records based on Contact ID
- Modern Workplace6 April 2024Download SharePoint library files in Power Pages with JavaScript and Cloud flows – Improved code using jQuery & option to open PDF file in a new tab
- Modern Workplace13 March 2024Handle multiple N:N records associate and disassociate requests with JavaScript and Power Pages Web API
- Modern Workplace17 February 2024Generic JavaScript Functions to Associate and Disassociate Dataverse records using the Power Pages Web API