I’m building a Gmail sidebar extension and need to get the user’s company domain or workspace identifier. I want to show different content based on which Google Workspace domain the user belongs to.
From what I can tell, Gmail sidebar extensions can’t directly access user information unless you implement OAuth authentication. I found an example that demonstrates retrieving user contacts through OAuth, and it uses specific API endpoints to fetch that data.
My main question is whether there’s an API endpoint or method to get the Google Workspace domain information for the current user. Is this even possible with Gmail extensions? Any guidance would be helpful.
same prob here. admin sdk dir api works, but ya gotta set domain-wide delegation or you’ll run into permisson errors. easy solution: just parse the email from gmail’s basic profile scope. get the domain from [email protected] - no need for extra permissions.
To retrieve the Google Workspace domain information in a Gmail sidebar extension, you must use OAuth for accessing user data. Specifically, the Directory API’s Users.get endpoint is key, as it allows you to fetch the user’s email and associated domain details. However, be cautious—only users with the appropriate Workspace permissions can access this data. Regular users typically lack the ability to view domain-level information, leading to potential authentication failures, as I’ve experienced myself. Alternatively, consider using the People API, which can provide some basic profile information, including the user’s domain inferred from their email address. It’s a more reliable approach when dealing with varying permission levels.
You can grab domain info without complex API calls using the basic profile scope that most Gmail extensions already need anyway. Just request the profile scope through OAuth and parse the user’s email to get their domain. I’ve built workspace extensions this way and it works reliably. If you need detailed org data, the Admin SDK Reports API gives you workspace metrics, but you’ll need admin privileges. I’d suggest a fallback approach: extract the domain from the email first, then try Admin SDK calls only if you’ve got enhanced permissions. This way you avoid auth errors but still get the core functionality your extension needs.