-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResourceServer.java
34 lines (25 loc) · 1.22 KB
/
ResourceServer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.elipcero.SpringOauth2MobileClient;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.AllArgsConstructor;
import lombok.NonNull;
@AllArgsConstructor
@RestController
public class ResourceServer {
@NonNull private final ProfileInformationService profileService;
@NonNull private final ConsumerTokenServices defaultTokenServices;
@RequestMapping("/hello")
public String getHelloWorld(OAuth2Authentication authentication) {
return String.format("Hello word User: (%s), Profile: (%s)",
authentication.getUserAuthentication().getName(),
this.profileService.GetProfile(authentication).toString());
}
@RequestMapping("/revokeToken")
public void revokeToken(OAuth2Authentication authentication) {
OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails)authentication.getDetails();
defaultTokenServices.revokeToken(details.getTokenValue());
}
}