web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / How to get the logging...
Power Pages
Suggested Answer

How to get the logging users email in Power Pages with Google Authenticator

(0) ShareShare
ReportReport
Posted on by
Hi @WarrenBelz @Pstork1 @RandyHayes and all,

I am trying to fetch the email ID of the logged-in user in Power Pages. I am using Google Authenticator for authentication, but I am facing an issue retrieving the actual email address of the Google user.

Here’s the issue:
  1. When logging in with Google Authenticator, I expect the system to fetch the email from Google (e.g., leocartworldjfyitd@gmail.com).

After logging in, the email does not match the Google user's email.


This is the new email I was expecting. Please refer to the screenshot below.


Is there a script I can write to retrieve the Google user's email and use the Web API to update the new Gmail address in the contact?

Alternatively, are there any Site Settings I can configure to map the Gmail address to the contact's emailaddress1 field?

Any suggestions or solutions would be helpful.

Thank you for your help
Categories:
I have the same question (0)
  • Suggested answer
    SaiRT14 Profile Picture
    1,990 Super User 2025 Season 2 on at
    Try the below and let me know how it goes:
     
    // Example function to capture logged-in user's email and update contact
    async function updateContactEmail() {
        try {
            // Assuming Power Pages provides a user context with email after authentication
            const userEmail = await getGoogleUserEmail(); // Replace with actual function if available
            if (!userEmail) {
                console.error("User email not available from Google Authenticator.");
                return;
            }
            // Get the logged-in user's contact ID
            const contactId = await getLoggedInContactId(); // Replace with actual function if available
            if (contactId) {
                // Update the contact's email address
                const apiUrl = `/api/data/v9.2/contacts(${contactId})`;
                const data = {
                    emailaddress1: userEmail
                };
                const response = await fetch(apiUrl, {
                    method: 'PATCH',
                    headers: {
                        'Content-Type': 'application/json',
                        'OData-MaxVersion': '4.0',
                        'OData-Version': '4.0',
                        'Accept': 'application/json'
                    },
                    body: JSON.stringify(data)
                });
                if (response.ok) {
                    console.log("Contact email updated successfully.");
                } else {
                    console.error("Failed to update contact email:", response.statusText);
                }
            } else {
                console.error("Contact ID not found.");
            }
        } catch (error) {
            console.error("Error updating contact email:", error);
        }
    }
    // Helper function to retrieve the Google user's email (for demonstration)
    async function getGoogleUserEmail() {
        // Use actual method to retrieve the authenticated user's email
        // Replace this with your authentication provider’s method to fetch user email
        return "leocartworldjfyitd@gmail.com"; // Example email
    }
    // Helper function to retrieve the logged-in user's contact ID (for demonstration)
    async function getLoggedInContactId() {
        // Use actual method to retrieve contact ID of the authenticated user
        return "GUID_OF_CONTACT_RECORD"; // Replace with actual contact ID
    }
    // Call the function on page load or after authentication
    updateContactEmail();
     
  • rulesrchanged1 Profile Picture
    on at
    So the email which shows up after user logs in comes from the claims sent back by google. Do u have this setup somewhere and i can quickly try it to see what does google sends back in claim. It is not possible to customize this today, but we are adding a new feature in January which will allow u to map email address field to any claim in auth token using a site setting.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 70 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 55

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard