I'm trying to setup an OAuth2 Authorization Server using Spring Boot and Spring Security's OAuth2 Integration.
When I try to authenticate I get a HTTP status code 400
response saying: "Bad Credentials".
Here you can find my Authorization Server and Web Security Configuration: https://gist.github.com/codecitizen/8d130469d83439f5fca86b1a84733aab
I have a custom implementation for UserDetailsService
and ClientDetailsService
. But they seem to be properly configured. When I run the following test case:
given().
formParam("grant_type", "password").
formParam("username", user.getUsername()).
formParam("password", password).
auth().basic(client.getClientId(), client.getClientSecret()).
when().
post("/oauth/token").
then().extract().asString();
using RestAssurred, both services are called.
Event stranger: When I set a Break Point in IntelliJ on this expression and evaluate it, it returns a proper JWT token and authentication seemed to have work. When I execute the test method again and to the exact same thing I get: {"error":"invalid_grant","error_description":"Bad credentials"}
this response! Without changing anything in the code!
I really cannot figure out what the problem is. Anyone experienced with Spring Security + OAuth2 who can help?