Spring Security – adding extra / custom attributes to Auth Server Introspection endpoint response

I’m implemeting a secure login feature with Spring Security.
I decided to go down the opaque token route (rather than JWT route)

  • I didn’t want to expose sensitive security information in the tokens
  • I wanted the ability to revoke tokens.

I have some things up and running

  • The client sends the authorisation code to the auth server
  • The auth server sends back a simple much shorter access token
  • The client sends that access token to the resource server (by calling any resource server endpoint)
  • The resource server then sends that access token to the auth server
  • The auth server then validates that (against some in-memory cache storing tokens, I’m guessing)
  • After validating, the auth server then returns either active = false, or active = true, with some other information (e.g. username, expiry date, issuance date, client scopes) back to the resourc server

Now, I want to be able to:

Point 1

  • When the auth server tries to validate the access token, to return extra information (such as the sensitive information I didn’t want to send in the opaque access token – such as the user’s authorisations, whether their account is expired, locked, enabled etc.)
  • Is there a way therefore of configuring the introspection end point response, such that on a successful validation, it makes another call to my database (via userDetailsService), to get these attributes, and embeds them in the response sent back to the resource server, so the resource server can then create it’s authentication object?

Point 2

  • Secondly, to reduce the number of calls between the auth server and resource server (as I think with introspection, a call is made on every http request), can I implement some kind of local caching system, so that when the resource server gets the opaque access token from the client, it first checks the cache for whether it had created an authentication object and uses that, rather than making an introspection call to the auth server. (The cache can have a short lifetime and be not more than the expiry date of the access token)
  • I can understand this might have small issues with token revokation since the auth server won’t introspect until the cache timing for that item has expired…unless there is a way to bypass that specifically for revokation?

Point 3

  • Should one bother trying to get the extra details in the auth server and sending them back through the introspection endpoint to the resource server, and just let the resource server get the extra details (with another duplicate userDetailsService), and let it create it’s own authenticaiton object from there…?

Here is the relevant part of auth server configuration code:
The resource server is the back-end registered client. It calls the auth server via the introspection end point
I don’t know how to though customise the introspection endpoint response though to include extra information obtained about the front end client, (via another database call):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@Bean
/* registeredClientRepository (defines: authorization grants, OIDC scopes, etc.) */
fun registeredClientRepository(): InMemoryRegisteredClientRepository {
// front-end client
val oidcClient = RegisteredClient.withId(UUID.randomUUID().toString())
.clientId("oidc-client")
.clientSecret(passwordEncoder.encode("secret"))
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
.authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN)
.redirectUri("https://www.aaa.com/authorized")
.postLogoutRedirectUri("https://www.aaa.com/authorized")
.tokenSettings(
TokenSettings.builder()
.accessTokenFormat(OAuth2TokenFormat.REFERENCE)
.accessTokenTimeToLive(Duration.ofHours(12))
.build())
.scope("OPAQUE")
.scopes { scopes -> scopes.addAll(listOf("read", "write")) }
.scope(OidcScopes.OPENID) // requests an ID token, which is necessary for any OpenID Connect request.
.scope(OidcScopes.PROFILE) // requests access to the user's profile information (e.g., name, date of birth)
.clientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build())
.build()
// back-end client
val resourceServer = RegisteredClient.withId(UUID.randomUUID().toString())
.clientId("resource_server")
.clientSecret(passwordEncoder.encode("resource_server_secret"))
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
.authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)
.build()
return InMemoryRegisteredClientRepository(oidcClient, resourceServer)
}
</code>
<code>@Bean /* registeredClientRepository (defines: authorization grants, OIDC scopes, etc.) */ fun registeredClientRepository(): InMemoryRegisteredClientRepository { // front-end client val oidcClient = RegisteredClient.withId(UUID.randomUUID().toString()) .clientId("oidc-client") .clientSecret(passwordEncoder.encode("secret")) .clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC) .authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE) .authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN) .redirectUri("https://www.aaa.com/authorized") .postLogoutRedirectUri("https://www.aaa.com/authorized") .tokenSettings( TokenSettings.builder() .accessTokenFormat(OAuth2TokenFormat.REFERENCE) .accessTokenTimeToLive(Duration.ofHours(12)) .build()) .scope("OPAQUE") .scopes { scopes -> scopes.addAll(listOf("read", "write")) } .scope(OidcScopes.OPENID) // requests an ID token, which is necessary for any OpenID Connect request. .scope(OidcScopes.PROFILE) // requests access to the user's profile information (e.g., name, date of birth) .clientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build()) .build() // back-end client val resourceServer = RegisteredClient.withId(UUID.randomUUID().toString()) .clientId("resource_server") .clientSecret(passwordEncoder.encode("resource_server_secret")) .clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC) .authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS) .build() return InMemoryRegisteredClientRepository(oidcClient, resourceServer) } </code>
@Bean
    /* registeredClientRepository (defines: authorization grants, OIDC scopes, etc.) */
    fun registeredClientRepository(): InMemoryRegisteredClientRepository {

        // front-end client
        val oidcClient = RegisteredClient.withId(UUID.randomUUID().toString())
            .clientId("oidc-client")
            .clientSecret(passwordEncoder.encode("secret"))
            .clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
            .authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
            .authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN)
            .redirectUri("https://www.aaa.com/authorized")
            .postLogoutRedirectUri("https://www.aaa.com/authorized")
            .tokenSettings(
                TokenSettings.builder()
            .accessTokenFormat(OAuth2TokenFormat.REFERENCE)
                .accessTokenTimeToLive(Duration.ofHours(12))
                .build())
            .scope("OPAQUE")
            .scopes { scopes -> scopes.addAll(listOf("read", "write")) }
            .scope(OidcScopes.OPENID) // requests an ID token, which is necessary for any OpenID Connect request.
            .scope(OidcScopes.PROFILE) // requests access to the user's profile information (e.g., name, date of birth)
            .clientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build())
            .build()

        // back-end client
        val resourceServer = RegisteredClient.withId(UUID.randomUUID().toString())
            .clientId("resource_server")
            .clientSecret(passwordEncoder.encode("resource_server_secret"))
            .clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
            .authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)
            .build()

        return InMemoryRegisteredClientRepository(oidcClient, resourceServer)
    }

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật