Skip to content

Missing response body for 401 response in resource server #5985

@ofir-popowski

Description

@ofir-popowski

When trying to access any protected endpoint without including an access token in the header, the response code is 401 (which is expected), but there's no response body, unlike older OAuth2 resource server.

The older versions of OAuth2 using @EnableResourceServer used to return 401 with the following body:

{
    "error": "unauthorized",
    "error_description": "Full authentication is required to access this resource"
}

Now it just returns an empty string.

This is easily testable when adding the following test to OAuth2ResourceServerApplicationITests.java

@Test
public void performWithoutTokenThenUnauthorized()
        throws Exception {

    this.mvc.perform(get("/"))
            .andExpect(status().isUnauthorized())
            .andExpect(content().string(containsString("")));
}

Using version 5.1.1.RELEASE like so:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-oauth2-resource-server</artifactId>
    <version>5.1.1.RELEASE</version>
</dependency>

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions