Get current logged user in Excel office-js add-in
Asked Answered
T

2

6

I would like to add to my Excel add-in a mechanism to keep track of the last user who performed certain action and the date it was performed. Is it possible to get information about the user currently logged to Excel from the add-in?

Thanks!

Toady answered 5/5, 2017 at 20:16 Comment(0)
M
6

As luck would have it, single sign-on (SSO) was released in developer preview the day before you posted your question. As part of the system, your add-in gets a token from the Office host application that contains a "preferred_username" property. The value of the property is the email of the user logged into Office.

There is an overview at Enable single sign-on for Office add-ins (preview).

There are two samples:

Office-Add-in-ASPNET-SSO

Office-Add-in-Nodejs-SSO

In both samples, the add-in also uses the token received from Office host to get an access token to Microsoft Graph, but your add-in doesn't have to take that extra step.

I don't know of any way of getting the user identity without using SSO.

Mossbunker answered 6/5, 2017 at 18:59 Comment(5)
Thanks! I will give it a try.Calica
Hi. Today I downloaded the ASPNET-SSO sample. When I tried to register the app using "localhost:44355" as Application ID URI, I got this error: "Your Application ID URI must be globally unique." If I change the port, I don't get the error. What does that address represent? Is the 44355 port important? Also, when I tried to build the sample, I got an error in the manifest file, saying that WebApplicationId is an invalid child of VersionOverrides. Any Ideas?Calica
@MarioSolís A couple of other people ran into the same issue. We have updated our guidance to solve this problem. The GitHub version of the instructions are now updated: github.com/OfficeDev/office-js-docs/blob/master/docs/develop/… The version on dev.office.com will updated in a few days. The fix is simple: Add the application GUID to the Application ID URI when registering the add-in and use the same value in the WebApplicationResource element in the add-in manifest.Mossbunker
Thanks! I think you reverted the GIT commit with the updated instructions (I checked the history and found your changes). I have a better understanding now. however, when I try to compile the project, I'm still getting this error "The element 'VersionOverrides' in namespace 'schemas.microsoft.com/office/taskpaneappversionoverrides' has invalid child element 'WebApplicationId' in namespace 'schemas.microsoft.com/office/taskpaneappversionoverrides'. List of possible elements expected: any element in namespace 'schemas.microsoft.com/office....'" incorrect schema maybe?Calica
I think I've fixed my Git goof. You need a very recent version of Visual Studio that recognizes the new markup. See the Prerequisites section of dev.office.com/docs/add-ins/develop/…Mossbunker
F
2

From the tags, it looks you are talking about javascript addins (office 365). Unfortunately (AFAIK) it is not currently possible to get user information in javascript addins.

Probably your question is more or less a duplicate of this one: How to get username, email address, filename from task pane app

Freida answered 5/5, 2017 at 21:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.