Skip to content

Commit 0c07477

Browse files
author
Steve Riesenberg
committed
Add activation page to sample
Issue spring-projectsgh-44
1 parent 99f2466 commit 0c07477

File tree

5 files changed

+97
-6
lines changed

5 files changed

+97
-6
lines changed

samples/device-grant-authorizationserver/src/main/java/sample/config/SecurityConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public class SecurityConfig {
6666
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
6767
OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http);
6868
http.getConfigurer(OAuth2AuthorizationServerConfigurer.class)
69+
.deviceAuthorizationEndpoint((deviceAuthorizationEndpoint) -> deviceAuthorizationEndpoint
70+
.deviceVerificationUri("/activate")
71+
)
6972
.oidc(Customizer.withDefaults()); // Enable OpenID Connect 1.0
7073

7174
// @formatter:off

samples/device-grant-authorizationserver/src/main/java/sample/web/DeviceController.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,34 @@
1616

1717
package sample.web;
1818

19-
import java.util.Map;
20-
19+
import org.springframework.stereotype.Controller;
2120
import org.springframework.web.bind.annotation.GetMapping;
22-
import org.springframework.web.bind.annotation.RestController;
21+
import org.springframework.web.bind.annotation.RequestParam;
2322

2423
/**
2524
* @author Steve Riesenberg
2625
*/
27-
@RestController
26+
@Controller
2827
public class DeviceController {
2928

29+
@GetMapping(value = "/activate", params = "!code")
30+
public String activate() {
31+
return "activate";
32+
}
33+
34+
@GetMapping(value = "/activate", params = "code")
35+
public String activateCode(@RequestParam("code") String userCode) {
36+
return "redirect:/oauth2/device_verification?user_code=" + userCode;
37+
}
38+
39+
@GetMapping("/activated")
40+
public String activated() {
41+
return "activated";
42+
}
43+
3044
@GetMapping(value = "/", params = "success")
31-
public Map<String, String> success() {
32-
return Map.of("message", "You have successfully activated your device.");
45+
public String success() {
46+
return "activated";
3347
}
3448

3549
}
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<title>Device Grant Example</title>
7+
<link rel="stylesheet" href="/webjars/bootstrap/css/bootstrap.css" th:href="@{/webjars/bootstrap/css/bootstrap.css}" />
8+
<style rel="stylesheet">
9+
html, body, .container, .jumbotron {
10+
height: 100%;
11+
}
12+
.jumbotron {
13+
margin-bottom: 0;
14+
}
15+
.gap {
16+
margin-top: 70px;
17+
}
18+
</style>
19+
</head>
20+
<body>
21+
<div class="jumbotron">
22+
<div class="container">
23+
<div class="row">
24+
<div class="col-md-8">
25+
<form th:action="@{/oauth2/device_verification}" method="get">
26+
<p>Enter the activation code to authorize the device.</p>
27+
<p class="gap">Activation Code</p>
28+
<div class="form-group">
29+
<label class="sr-only" for="user_code">Activation Code</label>
30+
<input type="text" class="form-control" id="user_code" name="user_code" placeholder="Activation Code" autofocus>
31+
</div>
32+
<button type="submit" class="btn btn-default">Submit</button>
33+
</form>
34+
</div>
35+
<div class="col-md-4">
36+
<img src="/assets/img/devices.png" th:src="@{/assets/img/devices.png}" class="img-responsive" alt="Devices">
37+
</div>
38+
</div>
39+
</div>
40+
</div>
41+
</body>
42+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<title>Device Grant Example</title>
7+
<link rel="stylesheet" href="/webjars/bootstrap/css/bootstrap.css" th:href="@{/webjars/bootstrap/css/bootstrap.css}" />
8+
<style rel="stylesheet">
9+
html, body, .container, .jumbotron {
10+
height: 100%;
11+
}
12+
.jumbotron {
13+
margin-bottom: 0;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
<div class="jumbotron">
19+
<div class="container">
20+
<div class="row">
21+
<div class="col-md-8">
22+
<h2>Success!</h2>
23+
<p>You have successfully activated your device. Please return to your device to continue.</p>
24+
</div>
25+
<div class="col-md-4">
26+
<img src="/assets/img/devices.png" th:src="@{/assets/img/devices.png}" class="img-responsive" alt="Devices">
27+
</div>
28+
</div>
29+
</div>
30+
</div>
31+
</body>
32+
</html>

0 commit comments

Comments
 (0)