2017-08-16 77 views
1

我的工作Excel Web Add-In。我正在使用OfficeDev/office-js-helpers庫來驗證用戶。以下代碼工作正常。但我不知道如何獲得用戶的電子郵件,用戶名等如何使用Office-js-helper的身份驗證獲取用戶信息?

是否有OfficeDev/office-js-helpers任何可用的功能,通過它我可以得到用戶信息?

if (OfficeHelpers.Authenticator.isAuthDialog()) { 
    return; 
} 

var authenticator = new OfficeHelpers.Authenticator(); 

// register Microsoft (Azure AD 2.0 Converged auth) endpoint using 
authenticator.endpoints.registerMicrosoftAuth('clientID'); 

// for the default Microsoft endpoint 
authenticator 
    .authenticate(OfficeHelpers.DefaultEndpoints.Microsoft) 
    .then(function (token) { 
    /* My code after authentication and here I need user's info */ }) 
    .catch(OfficeHelpers.Utilities.log); 

代碼示例將會非常有用。

回答

1

此代碼只爲您提供的token用戶。爲了獲得有關用戶的信息,你需要撥打電話到Microsoft Graph API。您可以在該網站上找到一整套文檔。

如果你只是爲了獲取配置文件信息驗證,我建議你看Enable single sign-on for Office Add-ins (preview)。這是爲用戶獲取訪問令牌的更簡潔的方法。目前它仍處於預覽狀態,所以它的可行性取決於您計劃部署加載項的位置。

+0

謝謝回答。在OfficeDev/office-js-helpers中沒有任何干淨的代碼示例可以獲取用戶的基本信息?您提供的鏈接的理論概念更多,但代碼樣本更少 – user3881465

相關問題