Skip to content

Commit 25b582c

Browse files
Steve Riesenbergwilkinsona
authored andcommitted
Add properties to support device grant
This commit adds the following properties under spring.security.oauth2.authorizationserver.client.[registration-id]: * endpoint.device-authorization-uri * endpoint.device-verification-uri * token.device-code-time-to-live See gh-34957
1 parent c3e739c commit 25b582c

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/server/servlet/OAuth2AuthorizationServerProperties.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ public static class Endpoint {
9999
*/
100100
private String authorizationUri;
101101

102+
/**
103+
* Authorization Server's OAuth 2.0 Device Authorization Endpoint.
104+
*/
105+
private String deviceAuthorizationUri;
106+
107+
/**
108+
* Authorization Server's OAuth 2.0 Device Verification Endpoint.
109+
*/
110+
private String deviceVerificationUri;
111+
102112
/**
103113
* Authorization Server's OAuth 2.0 Token Endpoint.
104114
*/
@@ -133,6 +143,22 @@ public void setAuthorizationUri(String authorizationUri) {
133143
this.authorizationUri = authorizationUri;
134144
}
135145

146+
public String getDeviceAuthorizationUri() {
147+
return this.deviceAuthorizationUri;
148+
}
149+
150+
public void setDeviceAuthorizationUri(String deviceAuthorizationUri) {
151+
this.deviceAuthorizationUri = deviceAuthorizationUri;
152+
}
153+
154+
public String getDeviceVerificationUri() {
155+
return this.deviceVerificationUri;
156+
}
157+
158+
public void setDeviceVerificationUri(String deviceVerificationUri) {
159+
this.deviceVerificationUri = deviceVerificationUri;
160+
}
161+
136162
public String getTokenUri() {
137163
return this.tokenUri;
138164
}
@@ -430,6 +456,11 @@ public static class Token {
430456
*/
431457
private String accessTokenFormat;
432458

459+
/**
460+
* Time-to-live for a device code.
461+
*/
462+
private Duration deviceCodeTimeToLive;
463+
433464
/**
434465
* Whether refresh tokens are reused or a new refresh token is issued when
435466
* returning the access token response.
@@ -470,6 +501,14 @@ public void setAccessTokenFormat(String accessTokenFormat) {
470501
this.accessTokenFormat = accessTokenFormat;
471502
}
472503

504+
public Duration getDeviceCodeTimeToLive() {
505+
return this.deviceCodeTimeToLive;
506+
}
507+
508+
public void setDeviceCodeTimeToLive(Duration deviceCodeTimeToLive) {
509+
this.deviceCodeTimeToLive = deviceCodeTimeToLive;
510+
}
511+
473512
public boolean isReuseRefreshTokens() {
474513
return this.reuseRefreshTokens;
475514
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/server/servlet/OAuth2AuthorizationServerPropertiesMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ AuthorizationServerSettings asAuthorizationServerSettings() {
5353
AuthorizationServerSettings.Builder builder = AuthorizationServerSettings.builder();
5454
map.from(this.properties::getIssuer).to(builder::issuer);
5555
map.from(endpoint::getAuthorizationUri).to(builder::authorizationEndpoint);
56+
map.from(endpoint::getDeviceAuthorizationUri).to(builder::deviceAuthorizationEndpoint);
57+
map.from(endpoint::getDeviceVerificationUri).to(builder::deviceVerificationEndpoint);
5658
map.from(endpoint::getTokenUri).to(builder::tokenEndpoint);
5759
map.from(endpoint::getJwkSetUri).to(builder::jwkSetEndpoint);
5860
map.from(endpoint::getTokenRevocationUri).to(builder::tokenRevocationEndpoint);
@@ -111,6 +113,7 @@ private TokenSettings getTokenSettings(Client client, PropertyMapper map) {
111113
map.from(token::getAuthorizationCodeTimeToLive).to(builder::authorizationCodeTimeToLive);
112114
map.from(token::getAccessTokenTimeToLive).to(builder::accessTokenTimeToLive);
113115
map.from(token::getAccessTokenFormat).as(OAuth2TokenFormat::new).to(builder::accessTokenFormat);
116+
map.from(token::getDeviceCodeTimeToLive).to(builder::deviceCodeTimeToLive);
114117
map.from(token::isReuseRefreshTokens).to(builder::reuseRefreshTokens);
115118
map.from(token::getRefreshTokenTimeToLive).to(builder::refreshTokenTimeToLive);
116119
map.from(token::getIdTokenSignatureAlgorithm)

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/server/servlet/OAuth2AuthorizationServerAutoConfigurationTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ void authorizationServerSettingsBeanShouldBeCreatedWhenPropertiesPresent() {
124124
this.contextRunner
125125
.withPropertyValues(PROPERTIES_PREFIX + ".issuer=https://example.com",
126126
PROPERTIES_PREFIX + ".endpoint.authorization-uri=/authorize",
127+
PROPERTIES_PREFIX + ".endpoint.device-authorization-uri=/device_authorization",
128+
PROPERTIES_PREFIX + ".endpoint.device-verification-uri=/device_verification",
127129
PROPERTIES_PREFIX + ".endpoint.token-uri=/token", PROPERTIES_PREFIX + ".endpoint.jwk-set-uri=/jwks",
128130
PROPERTIES_PREFIX + ".endpoint.token-revocation-uri=/revoke",
129131
PROPERTIES_PREFIX + ".endpoint.token-introspection-uri=/introspect",
@@ -134,6 +136,8 @@ void authorizationServerSettingsBeanShouldBeCreatedWhenPropertiesPresent() {
134136
AuthorizationServerSettings settings = context.getBean(AuthorizationServerSettings.class);
135137
assertThat(settings.getIssuer()).isEqualTo("https://example.com");
136138
assertThat(settings.getAuthorizationEndpoint()).isEqualTo("/authorize");
139+
assertThat(settings.getDeviceAuthorizationEndpoint()).isEqualTo("/device_authorization");
140+
assertThat(settings.getDeviceVerificationEndpoint()).isEqualTo("/device_verification");
137141
assertThat(settings.getTokenEndpoint()).isEqualTo("/token");
138142
assertThat(settings.getJwkSetEndpoint()).isEqualTo("/jwks");
139143
assertThat(settings.getTokenRevocationEndpoint()).isEqualTo("/revoke");

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/server/servlet/OAuth2AuthorizationServerPropertiesMapperTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ private OAuth2AuthorizationServerProperties.Client createClient() {
8989
token.setAccessTokenFormat("reference");
9090
token.setAccessTokenTimeToLive(Duration.ofSeconds(300));
9191
token.setRefreshTokenTimeToLive(Duration.ofHours(24));
92+
token.setDeviceCodeTimeToLive(Duration.ofMinutes(30));
9293
token.setReuseRefreshTokens(true);
9394
token.setIdTokenSignatureAlgorithm("rs512");
9495
return client;
@@ -99,6 +100,8 @@ void getAuthorizationServerSettingsWhenValidParametersShouldAdapt() {
99100
this.properties.setIssuer("https://example.com");
100101
OAuth2AuthorizationServerProperties.Endpoint endpoints = this.properties.getEndpoint();
101102
endpoints.setAuthorizationUri("/authorize");
103+
endpoints.setDeviceAuthorizationUri("/device_authorization");
104+
endpoints.setDeviceVerificationUri("/device_verification");
102105
endpoints.setTokenUri("/token");
103106
endpoints.setJwkSetUri("/jwks");
104107
endpoints.setTokenRevocationUri("/revoke");
@@ -110,6 +113,8 @@ void getAuthorizationServerSettingsWhenValidParametersShouldAdapt() {
110113
AuthorizationServerSettings settings = this.mapper.asAuthorizationServerSettings();
111114
assertThat(settings.getIssuer()).isEqualTo("https://example.com");
112115
assertThat(settings.getAuthorizationEndpoint()).isEqualTo("/authorize");
116+
assertThat(settings.getDeviceAuthorizationEndpoint()).isEqualTo("/device_authorization");
117+
assertThat(settings.getDeviceVerificationEndpoint()).isEqualTo("/device_verification");
113118
assertThat(settings.getTokenEndpoint()).isEqualTo("/token");
114119
assertThat(settings.getJwkSetEndpoint()).isEqualTo("/jwks");
115120
assertThat(settings.getTokenRevocationEndpoint()).isEqualTo("/revoke");

0 commit comments

Comments
 (0)