1
1
``` java [callback:Java Spring]
2
+
2
3
import java.net.URI ;
3
4
import java.net.http.HttpClient ;
4
5
import java.net.http.HttpRequest ;
@@ -21,7 +22,9 @@ public class App {
21
22
static final String OAUTH_CLIENT_SECRET = " CLIENT_SECRET" ;
22
23
23
24
@GetMapping (" /callback" )
24
- public String callback (HttpServletRequest request , HttpSession session ) throws Exception {
25
+ public String callback (
26
+ HttpServletRequest request ,
27
+ HttpSession session ) throws Exception {
25
28
Object sessionState = session. getAttribute(" oauth2_state" );
26
29
String stateParam = request. getParameter(" state" );
27
30
@@ -46,7 +49,9 @@ public class App {
46
49
String codeIdentifier = HexUtils . toHexString(randomBytes);
47
50
48
51
MessageDigest digest = MessageDigest . getInstance(" SHA-256" );
49
- byte [] codeChallengeBytes = digest. digest((codeIdentifier + OAUTH_CLIENT_SECRET ). getBytes(StandardCharsets . UTF_8 ));
52
+ byte [] codeChallengeBytes = digest
53
+ .digest((codeIdentifier + OAUTH_CLIENT_SECRET )
54
+ .getBytes(StandardCharsets . UTF_8 ));
50
55
String codeChallenge = HexUtils . toHexString(codeChallengeBytes);
51
56
52
57
String accessTokenUrl = pimUrl + " /connect/apps/v1/oauth2/token" ;
@@ -67,7 +72,8 @@ public class App {
67
72
. POST (BodyPublishers . ofString(json. toString()))
68
73
.build();
69
74
70
- HttpResponse<String > response = client. send(authorizeRequest, BodyHandlers . ofString());
75
+ HttpResponse<String > response = client
76
+ .send(authorizeRequest, BodyHandlers . ofString());
71
77
72
78
return response. body();
73
79
}
0 commit comments