---
title: "Discussion on \"Spring Security OAuth 2.0 Opaque Token Authentication\" | Hashnode"
description: "Discussion on \"Spring Security OAuth 2.0 Opaque Token Authentication\". How to implement an OpaqueTokenIntrospector and use method security"
url: "https://hashnode.com/posts/spring-security-oauth-20-opaque-token-authentication/620f373dd589905b41291ad9"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Spring Security OAuth 2.0 Opaque Token Authentication](https://alainelkhoury.hashnode.dev/spring-security-oauth-20-opaque-token-authentication?utm_source=hashnode&utm_medium=feed)

How to implement an OpaqueTokenIntrospector and use method security

Feb 18, 2022 · 8 min read · alainelkhoury.hashnode.dev  
Updated Mar 3, 2022  
Read the article

-   [#spring](https://hashnode.com/tag/spring)
-   [#springboot](https://hashnode.com/tag/springboot)
-   [#oauth](https://hashnode.com/tag/oauth)
-   [#java](https://hashnode.com/tag/java)

## Written by

[Alain ElKhoury](https://hashnode.com/@alainelkhoury)

@alainelkhoury · Beirut, Lebanon

  
[View profile](https://hashnode.com/@alainelkhoury)

Backend Engineer | AWS Certified DevOps Engineer | Kafka CCDAK

Backend Engineer, AWS Certified DevOps Engineer, Kafka CCDAK

## Responses 2

Markdown supported · ⌘↵ to post

[Chirag](https://hashnode.com/@chirag01)

[Mar 12, 2024](https://hashnode.com/posts/spring-security-oauth-20-opaque-token-authentication/620f373dd589905b41291ad9/comment/65eff42fdc37230bd8cd149e)

Hello Alian,

Great article! By the way I am following this article. I have implemented the flow for resource server. Now I want to implement a OAuth2 Client which is going to help me login and generate Opaque token and return as response which then I can forward to resource sever. Could help me this.

[Richard Maldonado](https://hashnode.com/@RichardM)

[Feb 21, 2022](https://hashnode.com/posts/spring-security-oauth-20-opaque-token-authentication/620f373dd589905b41291ad9/comment/62140e5d95c64c6eda4554ea)

I have a problem when use opaqueToken, the log say 401 no body. Do you know what is the problem?

org.springframework.security.authentication.AuthenticationServiceException: 401 : \[no body\] at org.springframework.security.oauth2.server.resource.authentication.OpaqueTokenAuthenticationProvider.getOAuth2AuthenticatedPrincipal(OpaqueTokenAuthenticationProvider.java:110) ~\[spring-security-oauth2-resource-server-5.6.1.jar:5.6.1\] at org.springframework.security.oauth2.server.resource.authentication.OpaqueTokenAuthenticationProvider.authenticate(OpaqueTokenAuthenticationProvider.java:94) ~\[spring-security-oauth2-resource-server-5.6.1.jar:5.6.1\] at org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter.doFilterInternal(BearerTokenAuthenticationFilter.java:130) ~\[spring-security-oauth2-resource-server-5.6.1.jar:5.6.1\] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:103) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:89) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:117) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:110) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:80) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:55) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:211) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:183) ~\[spring-security-web-5.6.1.jar:5.6.1\] at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:354) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:267) ~\[spring-web-5.3.15.jar:5.3.15\] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~\[spring-web-5.3.15.jar:5.3.15\] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~\[spring-web-5.3.15.jar:5.3.15\] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~\[spring-web-5.3.15.jar:5.3.15\] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at com.sespesoft.weps.affiliates.config.CorsFilterConfig.doFilter(CorsFilterConfig.java:34) ~\[classes/:na\] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1732) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~\[tomcat-embed-core-9.0.56.jar:9.0.56\] at java.base/java.lang.Thread.run(Thread.java:833) ~\[na:na\] Caused by: org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionException: 401 : \[no body\] at org.springframework.security.oauth2.server.resource.introspection.NimbusOpaqueTokenIntrospector.makeRequest(NimbusOpaqueTokenIntrospector.java:158) ~\[spring-security-oauth2-resource-server-5.6.1.jar:5.6.1\] at org.springframework.security.oauth2.server.resource.introspection.NimbusOpaqueTokenIntrospector.introspect(NimbusOpaqueTokenIntrospector.java:129) ~\[spring-security-oauth2-resource-server-5.6.1.jar:5.6.1\] at org.springframework.security.oauth2.server.resource.authentication.OpaqueTokenAuthenticationProvider.getOAuth2AuthenticatedPrincipal(OpaqueTokenAuthenticationProvider.java:103) ~\[spring-security-oauth2-resource-server-5.6.1.jar:5.6.1\] ... 57 common frames omitted Caused by: org.springframework.web.client.HttpClientErrorException$Unauthorized: 401 : \[no body\] at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:105) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:168) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:122) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:819) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:777) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:660) ~\[spring-web-5.3.15.jar:5.3.15\] at org.springframework.security.oauth2.server.resource.introspection.NimbusOpaqueTokenIntrospector.makeRequest(NimbusOpaqueTokenIntrospector.java:155) ~\[spring-security-oauth2-resource-server-5.6.1.jar:5.6.1\] ... 59 common frames omitted

[Alain ElKhoury](https://hashnode.com/@alainelkhoury)

[Feb 22, 2022](https://hashnode.com/posts/spring-security-oauth-20-opaque-token-authentication/620f373dd589905b41291ad9/comment/62140e5d95c64c6eda4554ea#reply-6214758fb8d3826eb56652ae)

Hello Richard,

you're using NimbusOpaqueTokenIntrospector not the implementation from this article right? If yes, I need some code snippets to help you, but I think you're not setting the Principal Object (the currently logged in use) correctly.

[Richard Maldonado](https://hashnode.com/@RichardM)

[Feb 23, 2022](https://hashnode.com/posts/spring-security-oauth-20-opaque-token-authentication/620f373dd589905b41291ad9/comment/62140e5d95c64c6eda4554ea#reply-62165bd93b11209c8fb4bd56)

Hello, that's correct, I am trying implement an authorization server with jwt and grant\_type authorization\_code. The authorization server response an access token and since the resource server I want verify with introspect if the token is active or no, but I have that error. Can you share the code or explain how do the authorization server? Thanks
