无效的身份验证令牌。访问令牌验证失败。观众无效

InvalidAuthenticationToken. Access token validation failure. Invalid audience

我正在使用 OAuth 2.0 客户端凭据授予的客户端凭据流。我已在我的 Azure 应用程序中授予必要的权限 Calendars.ReadWrite,这是 api 端点 'https://graph.microsoft.com/v1.0/me/events' 所需要的。我能够使用 api '/{tenant}/oauth2/v2.0/token' 从 Servicenow 获取令牌并将范围作为 myappURI/.default 传递。但是,在使用令牌使用 api 'https://graph.microsoft.com/v1.0/me/events' 发布事件时,我收到 'Code:InvalidAuthenticationToken. Message:Access token validation failure. Invalid audience' 错误。对此的任何帮助将不胜感激。

您需要为范围发送 https://graph.microsoft.com/.default

4. Get an access token:

You specify the pre-configured permissions by passing https://graph.microsoft.com/.default as the value for the scope parameter in the token request. See the scope parameter description in the token request below for details.

https://docs.microsoft.com/en-us/graph/auth-v2-service

在我的例子中,我发送的是 ID 令牌而不是访问令牌。

  • ID tokens are meant to be read by the OAuth client.
  • Access tokens are meant to be read by the resource server.
  • ID tokens are JWTs. Access tokens can be JWTs but may also be a random string.
  • ID tokens should never be sent to an API. Access tokens should never be read by the client.

来源:https://oauth.net/id-tokens-vs-access-tokens/