Using PCF to Detect Client IP Address in Canvas Apps

Using PCF to Detect Client IP Address in Canvas Apps


Understanding your users’ location can be critical in Canvas Apps, and ‘PCF Client IP Detection’ offers a strategic solution. This method utilizes a PCF control to pinpoint the client’s IP address effectively. In this guide, we’ll delve into how to integrate this capability into your app, with step-by-step instructions and expert support from our technical team. And, for those who might encounter difficulties, our technical team is here to assist you.

Determining Client’s IP Address in Canvas Apps

Several app builders often wonder about obtaining the current user’s IP address. Unfortunately, no direct method is built into the canvas app to fetch this information. But, there’s a workaround – creating a PCF component. There’s a notable control titled ‘allowlist IP Address’ developed by MVP Yash Agarwal, which is publicly accessible via the PCF Gallery.

Understanding ‘allowlist IP Address’ Control

Before diving into the technicalities, it’s essential to understand how this control operates. The control fetches data by making a request to an external web resource: This endpoint promptly returns the client’s IP address. However, it’s crucial to remember that since this control pulls data from an external source, it qualifies as a premium control, necessitating a premium Power Apps license.

Setting Up IP Address Control in Your App

To avoid the hassle of constructing the control and solution from the source, we’ve prepared a solution ready for download. Once you’ve secured the solution file, uploading it to your Power Apps workspace is a breeze. Navigate to the Solutions area in your maker portal and use the ‘Import solution’ feature.

Integrating the IP Address Detector in Canvas App

Within your canvas app, the next step involves integrating this control. Navigate to Insert > Get more components, head to the ‘Code’ tab, and choose the ‘allowlist’ component. After importing, you’ll notice the control listed in the ‘Insert’ panel on the left. Drag and drop this onto your canvas, and voila! The control will now display the client’s IP address.

Storing Client’s IP Address Efficiently

In most scenarios, merely displaying the IP isn’t enough. You might want to capture and store it for further processing or logging. To achieve this, use the following formula:

Set(clientIP, allowlistComponent.OutPut)

This command transfers the IP address to a variable named clientIP, which you can reference later. A handy tip: If you prefer to keep this control hidden from end-users, adjust the visible property of the allowlist control to false.

Conclusion: Fetching a client’s IP address in Canvas Apps might seem daunting at first. However, with the right tools and the PCF control discussed in this guide, the process becomes straightforward. It’s worth noting that employing this method does necessitate either a Power Apps per-user or a per-app license. If you have any queries or need further technical guidance, don’t hesitate to contact us.

About The Author