2017-07-03 14 views
1

Office 365ログインでExcelアドインを認証するためにADAL.jsライブラリを使用しています。私はこれに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

adalライブラリを使用する代わりに、office-js-helpersを使用して、暗黙のフローで外部サービスを承認することをお勧めします。

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); 

THIに関するキャッシュトークン

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'); 

より詳細な情報を入手:ここ

は、AzureのADアプリを使用して認証するためのコードスピネルでありますあなたは this linkを参照することができます。そして、文書の下にアドインもオフィスでのauthorizeに関する有用である:

Authorize external services in your Office Add-in

+0

これは私が期待されるソリューションに最も近いと思われます。ユーザーの電子メールを取得する方法はありますか? – immysl

+1

@immysl AFAIK、このライブラリは、ユーザーの電子メール(UPN?)を取得することをサポートしていません。この問題を回避するには、トークンをデコードして取得することができます。 –

+0

ありがとうございます。私はそれを試してみる:) – immysl

関連する問題