2017-07-03 92 views
1

我使用ADAL.js库用于验证我的Excel插件通过Office 365的登录。我为此使用了Azure AD应用程序,并且也授予了所需的权限。我使用的ADAL.js设置如下:没有用户信息保存与Office 365登录(ADAL.js)

var config = { 
    tenant: tenant, 
    clientId: clientId, 
    redirectUri: redirectUrl, 
    postLogoutRedirectUri: logoutUrl, 
    extraQueryParameter: 'scope=openid+profile', 
    cacheLocation: 'localStorage' 
}; 

登录工作正常。它正确地重定向到加载项主页,但不能使用getCachedUser函数检索用户信息。我得到的是一个null值。我在这里做错了什么?

回答

0

除了使用阿达尔库,微软建议使用office-js-helpers授权与隐含流动外部服务。

下面是一个代码尖晶石与天青AD应用来验证:

var authenticator = new OfficeHelpers.Authenticator(); 

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

// register Azure AD 1.0 endpoint using 
authenticator.endpoints.registerAzureADAuth('client id here', 'tenant here'); 

认证

// for the default AzureAD endpoint 
authenticator 
    .authenticate(OfficeHelpers.DefaultEndpoints.AzureAD) 
    .then(function (token) { /* Microsoft Token */ }) 
    .catch(OfficeHelpers.Utilities.log); 

获得一个高速缓存的令牌

authenticator 
    .authenticate('name of endpoint') 
    .then(function(token) { 
    /* 
     `token` is either cached or newly obtained upon expiry. 
    */ 
    }) 
    .catch(OfficeHelpers.Utilities.log); 

authenticator 
    .authenticate('name of endpoint', true /* force re-authentication */) 
    .then(function(token) { 
    /* 
     `token` is newly obtained. 
    */ 
    }) 
    .catch(OfficeHelpers.Utilities.log); 

// get the cached token if any. returns null otherwise. 
var token = authenticator.tokens.get('name of endpoint'); 

更多细节约THI您可以参考this link。以下文件也有利于有关授权的Office加载项:

Authorize external services in your Office Add-in

+0

这似乎是最接近我预想的解决方案。有没有办法获得用户的电子邮件? – immysl

+1

@immysl AFAIK,这个库不支持获取用户的邮件(UPN?)。作为一种解决方法,您可以通过解码令牌来获得它。 –

+0

谢谢。我会试试:) – immysl