2015-05-29 23 views
0

我正在嘗試創建一個小型客戶端webapp,其中adal.js(目前沒有角度部分)。從adal.js收到的令牌無效

我試圖登錄並獲得一個經過身份驗證的用戶對象。但是,我明顯從API中獲取了無效的OAuth令牌。

我發送到AuthenticationContext實例相關的配置:

var config = { 
    instance: 'https://login.microsoftonline.com/', 
    tenant: 'dbaa88b3-...', 
    clientId: 'f81bede8-...', 
    postLogoutRedirectUri: window.location.href, 
    cacheLocation: 'localStorage', 
}; 

不知道它的假設是租戶ID或租客的名字嗎?

然後當我認證我使用

var context = new AuthenticationContext(config); 
context.acquireToken(context.config.clientId, function(error, token) { 
     // error is null 
     var now = new Date(); 
     $.ajax({ 
      url: "https://outlook.office365.com/api/v1.0/me/calendarview", 
      method: "GET", 
      data: { 
      "startdatetime": (new Date()).toISOString(), 
      "enddatetime": (new Date()).toISOString() 
      }, 
      headers: { 
      "Authorization": "Bearer " + token, 
      "Accept": "application/json; odata.metadata=full", 
      "Client-Request-Id": clientid, // Some unique machine id? 
      "User-Agent": navigator.userAgent, 
      "Date": now.toUTCString() 
      } 
     }).then(function(result) {}, 
     function(e) { 
      console.error(e); 
      // 401 response, x-ms-diagnostics header = 2000005;reason="The PUID value was not found for [ORGID] identity.";error_category="invalid_user" 
     });  
}); 

如果我手動輸入上https://oauthplay.azurewebsites.net/與同一帳戶生成的認證令牌成功爲止。

+1

你可以用這個網站來解碼這兩個標記並比較:http://jwt.io –

回答

0

TL;博士不發送客戶端ID作爲第一個參數acquireToken如果你想訪問令牌

好像我用的是庫錯誤。

當您調用acquireToken並且您想要訪問令牌時,您不應該提供clientId作爲第一個參數,那麼您將獲得識別令牌(可以通過http://jwt.io/#工具得出結論,謝謝@ rich-randall)。至少我如何解讀code

所以我提供識別,而不是訪問令牌API,它不包含「PUID」值,因此錯誤消息:

// 401 response, x-ms-diagnostics header = 2000005;reason="The PUID value was not found for [ORGID] identity.";error_category="invalid_user" 

現在,我能夠從數據中提取API。