简体   繁体   English

simple-oauth2 在令牌刷新时抛出“内容类型与 JSON 不兼容”

[英]simple-oauth2 throws "The content-type is not JSON compatible" on token refresh

I'm using simple-oauth2 in this example to query Microsoft Graph.我在此示例中使用 simple-oauth2 来查询 Microsoft Graph。 All works well so far.到目前为止一切正常。 But when I try to refresh the access token var newToken = await storedToken.refresh();但是当我尝试刷新访问令牌var newToken = await storedToken.refresh(); , I get an error: ,我收到一个错误:

The content-type is not JSON compatible内容类型与 JSON 不兼容

This is thrown in wreck 's index.js and it seems like there is no content-type set in the headers, while the mode is set to strict .这是在wreckindex.js抛出的,似乎标题中没有设置content-type ,而mode设置为strict The problem is, that I have no idea how to change this or why this is happening.问题是,我不知道如何改变这一点或为什么会发生这种情况。 It only happens on refresh() .它只发生在refresh()

I figured this is a configuration problem.我认为这是一个配置问题。 The sample provides the config as follows示例提供的配置如下

OAUTH_AUTHORITY=https://login.microsoftonline.com/common
OAUTH_ID_METADATA=/v2.0/.well-known/openid-configuration
OAUTH_AUTHORIZE_ENDPOINT=/oauth2/v2.0/authorize
OAUTH_TOKEN_ENDPOINT=/oauth2/v2.0/token

wreck uses Url.URL to combine OAUTH_AUTHORITY with OAUTH_TOKEN_ENDPOINT which results in https://login.microsoftonline.com/oauth2/v2.0/token and therefore loses common . wreck 使用Url.URLOAUTH_AUTHORITYOAUTH_TOKEN_ENDPOINT组合OAUTH_AUTHORITY ,这导致https://login.microsoftonline.com/oauth2/v2.0/token并因此失去了common . This results in a 404 and therefore no JSON response anymore.这会导致404 ,因此不再有 JSON 响应。

I changed the config slightly and removed the leading slashes from the relative paths and added a trailing slash to the base URL.我稍微更改了配置并从相对路径中删除了前导斜杠,并在基本 URL 中添加了尾随斜杠。

OAUTH_AUTHORITY=https://login.microsoftonline.com/common/
OAUTH_ID_METADATA=/v2.0/.well-known/openid-configuration
OAUTH_AUTHORIZE_ENDPOINT=oauth2/v2.0/authorize
OAUTH_TOKEN_ENDPOINT=oauth2/v2.0/token

So that OAUTH_TOKEN_ENDPOINT is relative.所以OAUTH_TOKEN_ENDPOINT是相对的。 I have not figured why it worked for authorize though, but still works.我还没有弄清楚为什么它对授权有效,但仍然有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OAuth 2.0 in Node.js 访问令牌错误内容类型与 JSON 不兼容 - OAuth 2.0 in Node js Access Token Error The content-type is not JSON compatible 在将 Simple OAuth2 与 NodeJS 一起使用时,内容类型与 JSON 不兼容 - Content-type is not JSON compatible while using Simple OAuth2 with NodeJS 带有Simple-OAuth2和客户端凭据流的Microsoft Graph API - Microsoft Graph API with Simple-OAuth2 and Client Credentials Flow 如何使用Node.js和simple-oauth2对LinkedIn进行身份验证 - How to authenticate LinkedIn using Node.js and simple-oauth2 如何使用 simple-oauth2 库发出请求 application/x-www-form-urlencoded? - how to use the simple-oauth2 library to make request application/x-www-form-urlencoded? "如何摆脱 simple-oauth2 getToken 方法中的 400 bad request 错误?" - How to get rid of 400 bad request error in simple-oauth2 getToken method? 节点请求模块未将Content-Type设置为application / json - Node request module not setting Content-Type as application/json 将content-type标头设置为request.post的json - Set content-type header to json for request.post Sails js http post 请求,内容类型为:application/json - Sails js http post request with content-type: application/json 发送内容类型 json 而不是渲染页面 - sending content-type json instead of rendering page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM