-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathOauthClientConfiguration.java
More file actions
160 lines (140 loc) · 4.9 KB
/
Copy pathOauthClientConfiguration.java
File metadata and controls
160 lines (140 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.security.oauth2.configuration;
import io.micronaut.context.exceptions.ConfigurationException;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import io.micronaut.core.util.Toggleable;
import io.micronaut.security.oauth2.client.clientcredentials.ClientCredentialsConfiguration;
import io.micronaut.security.oauth2.configuration.endpoints.OauthAuthorizationEndpointConfiguration;
import io.micronaut.security.oauth2.configuration.endpoints.SecureEndpointConfiguration;
import io.micronaut.security.oauth2.endpoint.AuthenticationMethods;
import io.micronaut.security.oauth2.endpoint.DefaultSecureEndpoint;
import io.micronaut.security.oauth2.endpoint.SecureEndpoint;
import io.micronaut.security.oauth2.endpoint.endsession.request.AuthorizationServer;
import io.micronaut.security.oauth2.grants.GrantType;
import java.time.Duration;
import java.util.List;
import java.util.Optional;
/**
* OAuth 2.0 client configuration.
*
* @author Sergio del Amo
* @since 1.2.0
*/
public interface OauthClientConfiguration extends Toggleable {
String DEFAULT_AUTH_METHOD = AuthenticationMethods.CLIENT_SECRET_POST;
/**
* The default advanced expiration value for client credentials grant.
*/
Duration DEFAULT_ADVANCED_EXPIRATION = Duration.ofSeconds(30);
/**
* @return The provider name
*/
@NonNull
String getName();
/**
* @return The client id
*/
@NonNull
String getClientId();
/**
* @return The client secret
*/
@Nullable
String getClientSecret();
/**
* @return The scopes requested
*/
@NonNull
List<String> getScopes();
/**
* @return The grant type
*/
@NonNull
GrantType getGrantType();
/**
* @see <a href="https://tools.ietf.org/html/rfc6749#section-4.1.3">RFC 6749 Section 4.1.3</a>
* @return The optional token endpoint configuration
*/
Optional<SecureEndpointConfiguration> getToken();
/**
* @see <a href="https://tools.ietf.org/html/rfc6749#section-3.1">RFC 6749 Section 3.1</a>
* @return The optional authorization endpoint configuration
*/
Optional<OauthAuthorizationEndpointConfiguration> getAuthorization();
/**
*
* @return The Client Credentials Configuration
*/
@NonNull
Optional<ClientCredentialsConfiguration> getClientCredentials();
/**
* @see <a href="https://tools.ietf.org/html/rfc7662">RFC 7662</a>
* @return The introspection endpoint configuration
*/
Optional<SecureEndpointConfiguration> getIntrospection();
/**
* @see <a href="https://tools.ietf.org/html/rfc7009">RFC 7009</a>
* @return The revocation endpoint configuration
*/
Optional<SecureEndpointConfiguration> getRevocation();
/**
* @return The optional OpenID configuration
*/
Optional<OpenIdClientConfiguration> getOpenid();
/**
*
* @return The Token endpoint
* @throws ConfigurationException if token endpoint url is not set in configuration
*/
default SecureEndpoint getTokenEndpoint() throws ConfigurationException {
return getToken().map(secureEndpointConfiguration -> new DefaultSecureEndpoint(secureEndpointConfiguration, DEFAULT_AUTH_METHOD))
.orElseThrow(() -> new ConfigurationException("Oauth client " + getName() + " requires the token endpoint configuration to be set in configuration"));
}
/**
* @return The {@link AuthorizationServer} used by the OAuth Client.
* @since 4.15.0
*/
@Nullable
default AuthorizationServer getAuthorizationServer() {
return null;
}
/**
*
* @return Whether a request to /.well-known/oauth-authorization-server should be proxied to the authorization server.
* @since 4.15.0
*/
default boolean isProxyWellKnownOauthAuthorizationServer() {
return false;
}
/**
*
* @return Whether a request to /.well-known/openid-configuration should be proxied to the authorization server.
* @since 4.15.0
*/
default boolean isProxyWellKnownOpenidConfiguration() {
return false;
}
/**
* @since 5.1.0
* @return A new OAuth client configuration builder.
*/
@NonNull
static OauthClientConfigurationBuilder builder() {
return new OauthClientConfigurationBuilder();
}
}