我正在尝试在我的spring应用程序中实现Intercom OAuth2。我遇到了一个奇怪的问题。
一旦用户授予应用程序使用其数据的权限,就会向访问令牌uri(https://api.intercom.io/auth/eagle/token
)发送POST请求。此帖子请求由spring处理。
但后来我得到了错误
Caused by: org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException: Access token denied.
at org.springframework.security.oauth2.client.token.OAuth2AccessTokenSupport.retrieveToken(OAuth2AccessTokenSupport.java:142) ~[spring-security-oauth2-2.0.10.RELEASE.jar:na]
at org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider.obtainAccessToken(AuthorizationCodeAccessTokenProvider.java:209) ~[spring-security-oauth2-2.0.10.RELEASE.jar:na]
at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainNewAccessTokenInternal(AccessTokenProviderChain.java:143) ~[spring-security-oauth2-2.0.10.RELEASE.jar:na]
at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainAccessToken(AccessTokenProviderChain.java:119) ~[spring-security-oauth2-2.0.10.RELEASE.jar:na]
at org.springframework.security.oauth2.client.OAuth2RestTemplate.acquireAccessToken(OAuth2RestTemplate.java:221) ~[spring-security-oauth2-2.0.10.RELEASE.jar:na]
at org.springframework.security.oauth2.client.OAuth2RestTemplate.getAccessToken(OAuth2RestTemplate.java:173) ~[spring-security-oauth2-2.0.10.RELEASE.jar:na]
at org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter.attemptAuthentication(OAuth2ClientAuthenticationProcessingFilter.java:105) ~[spring-security-oauth2-2.0.10.RELEASE.jar:na]
... 56 common frames omitted
Caused by: org.springframework.security.oauth2.common.exceptions.OAuth2Exception: OAuth Error
at org.springframework.security.oauth2.common.exceptions.OAuth2ExceptionJackson2Deserializer.deserialize(OAuth2ExceptionJackson2Deserializer.java:119) ~[spring-security-oauth2-2.0.10.RELEASE.jar:na]
at org.springframework.security.oauth2.common.exceptions.OAuth2ExceptionJackson2Deserializer.deserialize(OAuth2ExceptionJackson2Deserializer.java:33) ~[spring-security-oauth2-2.0.10.RELEASE.jar:na]
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789) ~[jackson-databind-2.8.1.jar:2.8.1]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2913) ~[jackson-databind-2.8.1.jar:2.8.1]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:225) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readInternal(AbstractJackson2HttpMessageConverter.java:205) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:193) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.security.oauth2.client.token.OAuth2AccessTokenSupport$AccessTokenErrorHandler.handleError(OAuth2AccessTokenSupport.java:235) ~[spring-security-oauth2-2.0.10.RELEASE.jar:na]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:667) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:620) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:588) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.security.oauth2.client.token.OAuth2AccessTokenSupport.retrieveToken(OAuth2AccessTokenSupport.java:137) ~[spring-security-oauth2-2.0.10.RELEASE.jar:na]
... 62 common frames omitted
04:39:57.150 [http-nio-8080-exec-2] D
调试后,我发现由于缺少client_id,POST请求失败。这是我收到的json的一部分。
"errors":[{"code":"parameter_not_found","message":"client_id not specified"}
我的oauth.properties
文件同时包含client_id
和client_secret
。
intercom.client.clientId=MY_CLIENT_ID
intercom.client.clientSecret=MY_CLIENT_SECRET
intercom.client.userAuthorizationUri=https://app.intercom.io/oauth
intercom.client.accessTokenUri=https://api.intercom.io/auth/eagle/token
但是当我为github
,google
等其他oauth提供程序执行相同操作时,它可以正常工作。我甚至通过curl使用client_id
和client_secret
尝试了POST请求,请求成功,我得到了令牌。我无法理解为什么spring会在这里造成错误。虽然它适用于其他oauth提供商。
任何人都可以帮助我。为什么会发生这种情况?我似乎无法找到问题。谢谢!!