Skip to content

Commit 7896a84

Browse files
committed
fix(): Java spring App snippet formatting
1 parent 0ba7d07 commit 7896a84

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

content/apps/create-app/activate-java.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
```java [activate:Java Spring]
2+
23
import java.security.SecureRandom;
34

45
import javax.servlet.http.HttpServletRequest;
@@ -15,7 +16,10 @@ public class App {
1516
static final String OAUTH_SCOPES = "read_products write_products";
1617

1718
@GetMapping("/activate")
18-
public void activate(HttpServletRequest request, HttpSession session, HttpServletResponse response) throws Exception {
19+
public void activate(
20+
HttpServletRequest request,
21+
HttpSession session,
22+
HttpServletResponse response) throws Exception {
1923
// Create a random state for preventing cross-site request forgery
2024
byte[] randomBytes = new byte[10];
2125
new SecureRandom().nextBytes(randomBytes);
@@ -32,7 +36,8 @@ public class App {
3236

3337
// Build url for the Authorization Request
3438
// https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1
35-
String authorizeUrl = pimUrl + "/connect/apps/v1/authorize" + "?response_type=code" + "&client_id=" + OAUTH_CLIENT_ID
39+
String authorizeUrl = pimUrl + "/connect/apps/v1/authorize" + "?response_type=code"
40+
+ "&client_id=" + OAUTH_CLIENT_ID
3641
+ "&scope=" + OAUTH_SCOPES + "&state=" + state;
3742

3843
// Redirect the user to the Authorization URL

content/apps/create-app/callback-java.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
```java [callback:Java Spring]
2+
23
import java.net.URI;
34
import java.net.http.HttpClient;
45
import java.net.http.HttpRequest;
@@ -21,7 +22,9 @@ public class App {
2122
static final String OAUTH_CLIENT_SECRET = "CLIENT_SECRET";
2223

2324
@GetMapping("/callback")
24-
public String callback(HttpServletRequest request, HttpSession session) throws Exception {
25+
public String callback(
26+
HttpServletRequest request,
27+
HttpSession session) throws Exception {
2528
Object sessionState = session.getAttribute("oauth2_state");
2629
String stateParam = request.getParameter("state");
2730

@@ -46,7 +49,9 @@ public class App {
4649
String codeIdentifier = HexUtils.toHexString(randomBytes);
4750

4851
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));
5055
String codeChallenge = HexUtils.toHexString(codeChallengeBytes);
5156

5257
String accessTokenUrl = pimUrl + "/connect/apps/v1/oauth2/token";
@@ -67,7 +72,8 @@ public class App {
6772
.POST(BodyPublishers.ofString(json.toString()))
6873
.build();
6974

70-
HttpResponse<String> response = client.send(authorizeRequest, BodyHandlers.ofString());
75+
HttpResponse<String> response = client
76+
.send(authorizeRequest, BodyHandlers.ofString());
7177

7278
return response.body();
7379
}

0 commit comments

Comments
 (0)