2017-02-21 9 views
0

私のアプリケーションにSharepoint Onlineへのサイレント認証を実装しようとしています。私はOffice365接続サービスを追加しました。私は、単に2つのテキストボックスにトークンと有効期限を入力するテストページを使用しています。私は正常に動作し、次のコード(非サイレントAUTH)を持っている:認証コンテキストトークンキャッシュが定義されていません

document.addEventListener('deviceready', function() { 
$(document).ready(function() { 
    var authContext = Microsoft.ADAL.AuthenticationContext; 
    authContext.createAsync("https://login.microsoftonline.com/common/") 
     .then(function (authContext) { 
      authContext.acquireTokenAsync(
       "https://my.sharepoint.com",  // Resource URI 
       "4be098f8-2184-4831-9ef7-3d17dbbef6a0",  // Client ID 
       "http://localhost:4400/services/office365/redirectTarget.html" // Redirect URI 
      ).then(function (authResult) { 
       $('#token').value = authResult.accessToken; 
       $('#expire').value = authResult.expiresOn; 
      }, function (err) { 
       console.log(err); 
      }); 
     }, function (err) { 
      console.log(err); 
     }); 
}); 
}); 

私はその後、以下のコードを使用してAUTHサイレントを実装しようとしています:

document.addEventListener('deviceready', function() { 
$(document).ready(function() { 
    var authContext = Microsoft.ADAL.AuthenticationContext; 
    authContext.tokenCache.readItems().then(function (items) { 
     if (items.length > 0) { 
      authority = items[0].authority; 
      authContext = new Microsoft.ADAL.AuthenticationContext(authority); 
     } 
     authContext.acquireTokenSilentAsync("https://my.sharepoint.com", "4be098f8-2184-4831-9ef7-3d17dbbef6a0").then 
     (function (authResult) { 
      $('#token').value = authResult.accessToken; 
      $('#expire').value = authResult.expiresOn; 
     }, 
     function (authContext) { 
      authContext.acquireTokenAsync(
       "https://my.sharepoint.com",  // Resource URI 
       "4be098f8-2184-4831-9ef7-3d17dbbef6a0",  // Client ID 
       "http://localhost:4400/services/office365/redirectTarget.html" // Redirect URI 
      ).then(function (authResult) { 
       $('#token').value = authResult.accessToken; 
       $('#expire').value = authResult.expiresOn; 
      }, function (err) { 
       console.log(err); 
      }); 
     }, function (err) { 
      console.log(err); 
     } 
     ) 
    }); 
}); 
}); 

しようとしたとき、私はエラーを取得していますトークンキャッシュを読み取るために、私は未定義としてtokencacheを取得しています。私が見たすべてのサンプルはトークンキャッシュを参照するので、なぜそれが定義されないのか疑問に思っていますか?

答えて

0

トークンキャッシュにアクセスする前に、私のauthContextオブジェクトを作成する必要がありました... whoops

関連する問題