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);
}
)
});
});
});
我收到錯誤讀取令牌緩存,我得到的未定義的令牌緩存。我看過的每個示例都提到了令牌緩存,所以只是想知道它爲什麼會不明確?