1

如果我去https://developer.microsoft.com/en-us/graph/graph-explorer#并使用如下 URL:

https://graph.microsoft.com/beta/sites/4development106.sharepoint.com:/sites/DBSchenker:/lists/OEC_Docs/items 我可以看到请求成功。

现在,如果我使用来自 github https://github.com/AzureAD/microsoft-authentication-library-for-js的 Angular 应用程序

和像这样的代码

 private sharePointHost: string = "https://4development106.sharepoint.com/sites/DBSchenker/_api/web/lists/getByTitle('OEC_Docs')/items"

  getDocuments(token){
    const httpOptions = {
      headers: new HttpHeaders({
          'Accept':  'application/json;odata=verbose'
          ,'Authorization' : "Bearer " + token
        })
      };

    this.http.get(this.sharePointHost, httpOptions).subscribe(
      (resp) => console.log("respon is::: " + JSON.stringify(resp)),
      (err) => console.log("error:::" + JSON.stringify(err))
    )
  }

它抛出:

error:::`{"headers":{"normalizedNames":{},"lazyUpdate":null},"status":401,"statusText":"OK","url":"https://4development106.sharepoint.com/sites/DBSchenker/_api/web/lists/getByTitle('OEC_Docs')/items","ok":false,"name":"HttpErrorResponse","message":"Http failure response for https://4development106.sharepoint.com/sites/DBSchenker/_api/web/lists/getByTitle('OEC_Docs')/items: 401 OK","error":{"error_description":"Invalid JWT token. No certificate thumbprint specified in token header."}}`

将主机更改为(在图形 api 资源管理器中工作)

private sharePointHost: string = "https://graph.microsoft.com/beta/sites/4development106.sharepoint.com:/sites/DBSchenker:/lists/OEC_Docs/items"

投掷

error:::{"headers":{"normalizedNames":{},"lazyUpdate":null},"status":401,"statusText":"Unauthorized","url":"https://graph.microsoft.com/beta/sites/4development106.sharepoint.com:/sites/DBSchenker:/lists/OEC_Docs/items","ok":false,"name":"HttpErrorResponse","message":"Http failure response for https://graph.microsoft.com/beta/sites/4development106.sharepoint.com:/sites/DBSchenker:/lists/OEC_Docs/items: 401 Unauthorized","error":{"error":{"code":"InvalidAuthenticationToken","message":"Access token validation failure.","innerError":{"request-id":"f5a77afc-0d92-49a0-92c4-e727e056d0a9","date":"2018-10-30T01:42:02"}}}}

不知道我做错了什么

4

1 回答 1

0

我一直有同样的问题。我能找到的唯一解决方案是暂时使用 ADAL 而不是 MSAL。我不太清楚为什么,但 SharePoint Online 似乎只能以您使用它的方式与 ADAL 一起使用。

最初我认为这可能是因为 MSAL 中的“通用”端点,但切换到“仅此组织目录中的帐户 (...)”也没有解决问题。

您可能还想查看https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/521的类似问题(尽管这也没有解决我的问题)。

于 2019-02-19T13:21:20.317 回答