I created a simple authorization server, but I can’t configure it.
- Launch both applications (8080 for the auth server and 9999 for the client).
- Go to
localhost:9999/clientand redirect to localhost:8080/login(as expected). - Fill in the registration form with user / user.
- Get redirected to
localhost:9999/client(as expected), but Hello, nullinstead Hello, user.
However, if you go straight to localhost:8080/me, I have {"name":"user"}. How can i get it Hello, user?
Authorization server
@RestController
@EnableAuthorizationServer
@SpringBootApplication
public class Application extends WebSecurityConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@GetMapping({ "/user", "/me" })
public Map<String, String> user(Principal principal) {
return Collections.singletonMap("name", principal == null ? "null" : principal.getName());
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user").password("user").authorities(AuthorityUtils.NO_AUTHORITIES);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin();
}
}
Application properties
security:
oauth2:
client:
client-id: clientid
client-secret: clientsecret
scope: read,write
auto-approve-scopes: '.*'
Client
@Configuration
@EnableAutoConfiguration
@EnableOAuth2Sso
@RestController
public class Client {
@GetMapping("/")
public String home(Principal principal) {
return "Hello, " + principal.getName();
}
public static void main(String[] args) {
new SpringApplicationBuilder(Client.class)
.properties("spring.config.name=client").run(args);
}
}
Client Properties
server:
port: 9999
context-path: /client
security:
oauth2:
client:
client-id: clientid
client-secret: clientsecret
access-token-uri: http://localhost:8080/oauth/token
user-authorization-uri: http://localhost:8080/oauth/authorize
resource:
user-info-uri: http://localhost:8080/me
UPDATE:
, , ssoFilter, OAuth2. loginForm.
example GitHub. , .