Skip to content

Commit 95ef79a

Browse files
committed
Use custom consent page for device code flow
Issue gh-1189
1 parent e8c0837 commit 95ef79a

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

samples/featured-authorizationserver/src/main/java/sample/config/AuthorizationServerConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(
102102
.deviceAuthorizationEndpoint(deviceAuthorizationEndpoint ->
103103
deviceAuthorizationEndpoint.verificationUri("/activate")
104104
)
105+
.deviceVerificationEndpoint(deviceVerificationEndpoint ->
106+
deviceVerificationEndpoint.consentPage(CUSTOM_CONSENT_PAGE_URI)
107+
)
105108
.clientAuthentication(clientAuthentication ->
106109
clientAuthentication
107110
.authenticationConverter(deviceClientAuthenticationConverter)

samples/featured-authorizationserver/src/main/java/sample/web/AuthorizationConsentController.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public AuthorizationConsentController(RegisteredClientRepository registeredClien
5252
public String consent(Principal principal, Model model,
5353
@RequestParam(OAuth2ParameterNames.CLIENT_ID) String clientId,
5454
@RequestParam(OAuth2ParameterNames.SCOPE) String scope,
55-
@RequestParam(OAuth2ParameterNames.STATE) String state) {
55+
@RequestParam(OAuth2ParameterNames.STATE) String state,
56+
@RequestParam(name = OAuth2ParameterNames.USER_CODE, required = false) String userCode) {
5657

5758
// Remove scopes that were already approved
5859
Set<String> scopesToApprove = new HashSet<>();
@@ -82,6 +83,12 @@ public String consent(Principal principal, Model model,
8283
model.addAttribute("scopes", withDescription(scopesToApprove));
8384
model.addAttribute("previouslyApprovedScopes", withDescription(previouslyApprovedScopes));
8485
model.addAttribute("principalName", principal.getName());
86+
model.addAttribute("userCode", userCode);
87+
if (StringUtils.hasText(userCode)) {
88+
model.addAttribute("requestURI", "/oauth2/device_verification");
89+
} else {
90+
model.addAttribute("requestURI", "/oauth2/authorize");
91+
}
8592

8693
return "consent";
8794
}

samples/featured-authorizationserver/src/main/resources/templates/consent.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,24 @@ <h1 class="text-center text-primary">App permissions</h1>
2828
</p>
2929
</div>
3030
</div>
31+
<div th:if="${userCode}" class="row">
32+
<div class="col text-center">
33+
<p class="alert alert-warning">You have provided the code
34+
<span class="font-weight-bold" th:text="${userCode}"></span>.
35+
Verify that this code matches what is shown on your device.
36+
</p>
37+
</div>
38+
</div>
3139
<div class="row pb-3">
3240
<div class="col text-center"><p>The following permissions are requested by the above app.<br/>Please review
3341
these and consent if you approve.</p></div>
3442
</div>
3543
<div class="row">
3644
<div class="col text-center">
37-
<form name="consent_form" method="post" th:action="@{/oauth2/authorize}">
45+
<form name="consent_form" method="post" th:action="${requestURI}">
3846
<input type="hidden" name="client_id" th:value="${clientId}">
3947
<input type="hidden" name="state" th:value="${state}">
48+
<input th:if="${userCode}" type="hidden" name="user_code" th:value="${userCode}">
4049

4150
<div th:each="scope: ${scopes}" class="form-group form-check py-1">
4251
<input class="form-check-input"

0 commit comments

Comments
 (0)