How to get username, email address, filename from task pane app
Asked Answered
R

3

8

I cam trying to get the following information from the task pane app (Office Add-ins):

  1. User information ie. username, email address
  2. Filename of the current open document

I'm currently developing an task pane add in for Word, Excel and PowerPoint, as well as an Outlook app. Please advise.

Repression answered 28/3, 2016 at 11:22 Comment(2)
I don't believe you can get the username, yet. Vote for that feature here on UserVoice: officespdev.uservoice.com/forums/…Brehm
You can get the filename from Office.context.document.url in Excel.Brehm
Y
3

Single sign-on (SSO) was released in developer preview last week. 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.

Yogh answered 8/5, 2017 at 17:4 Comment(2)
Is it required to have the Azure subscription to use SSO in Addin?Cornellcornelle
@DennisMeissel Yes. But I believe that if you have an M365 subscription, there is an Azure subscription associated with it. Try logging into the Azure portal with the credentials of an admin on your M365 account.Yogh
C
2

There is currently no Office API that allows you to retrieve the user info. However, you could always use Active Directory Authentication Library (ADAL) to get the user's identity. Even though it's not perfect, it should work. Feel free to request an API for that on the Office Extensibility Platform's UserVoice.

Coltin answered 30/3, 2016 at 15:5 Comment(0)
A
1

There is no way to get the username/email from Word/Excel/PowerPoint. You can in Outlook via Office.context.mailbox.userProfile

Likewise, filename doesn't make sense from Outlook, but you can get document.url and document.getFilePropertiesAsync from the others (not sure but I expect document.url is the value when the document or add-in was loaded while getFilePropertiesAsync would be more up to date).

Align answered 28/3, 2016 at 14:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.