5
5
// Please see LICENSE in the repository root for full details.
6
6
7
7
use chrono:: { DateTime , Utc } ;
8
- use mas_iana:: {
9
- jose:: JsonWebSignatureAlg ,
10
- oauth:: { OAuthAuthorizationEndpointResponseType , OAuthClientAuthenticationMethod } ,
11
- } ;
8
+ use mas_iana:: { jose:: JsonWebSignatureAlg , oauth:: OAuthClientAuthenticationMethod } ;
12
9
use mas_jose:: jwk:: PublicJsonWebKeySet ;
13
- use oauth2_types:: { oidc:: ApplicationType , requests:: GrantType } ;
10
+ use oauth2_types:: {
11
+ oidc:: ApplicationType ,
12
+ registration:: { ClientMetadata , Localized } ,
13
+ requests:: GrantType ,
14
+ } ;
14
15
use rand:: RngCore ;
15
16
use serde:: Serialize ;
16
17
use thiserror:: Error ;
@@ -41,10 +42,6 @@ pub struct Client {
41
42
/// Array of Redirection URI values used by the Client
42
43
pub redirect_uris : Vec < Url > ,
43
44
44
- /// Array containing a list of the OAuth 2.0 `response_type` values that the
45
- /// Client is declaring that it will restrict itself to using
46
- pub response_types : Vec < OAuthAuthorizationEndpointResponseType > ,
47
-
48
45
/// Array containing a list of the OAuth 2.0 Grant Types that the Client is
49
46
/// declaring that it will restrict itself to using.
50
47
pub grant_types : Vec < GrantType > ,
@@ -123,6 +120,55 @@ impl Client {
123
120
}
124
121
}
125
122
123
+ /// Create a client metadata object for this client
124
+ pub fn into_metadata ( self ) -> ClientMetadata {
125
+ let ( jwks, jwks_uri) = match self . jwks {
126
+ Some ( JwksOrJwksUri :: Jwks ( jwks) ) => ( Some ( jwks) , None ) ,
127
+ Some ( JwksOrJwksUri :: JwksUri ( jwks_uri) ) => ( None , Some ( jwks_uri) ) ,
128
+ _ => ( None , None ) ,
129
+ } ;
130
+ ClientMetadata {
131
+ redirect_uris : Some ( self . redirect_uris . clone ( ) ) ,
132
+ response_types : None ,
133
+ grant_types : Some ( self . grant_types . into_iter ( ) . map ( Into :: into) . collect ( ) ) ,
134
+ application_type : self . application_type . clone ( ) ,
135
+ client_name : self . client_name . map ( |n| Localized :: new ( n, [ ] ) ) ,
136
+ logo_uri : self . logo_uri . map ( |n| Localized :: new ( n, [ ] ) ) ,
137
+ client_uri : self . client_uri . map ( |n| Localized :: new ( n, [ ] ) ) ,
138
+ policy_uri : self . policy_uri . map ( |n| Localized :: new ( n, [ ] ) ) ,
139
+ tos_uri : self . tos_uri . map ( |n| Localized :: new ( n, [ ] ) ) ,
140
+ jwks_uri,
141
+ jwks,
142
+ id_token_signed_response_alg : self . id_token_signed_response_alg ,
143
+ userinfo_signed_response_alg : self . userinfo_signed_response_alg ,
144
+ token_endpoint_auth_method : self . token_endpoint_auth_method ,
145
+ token_endpoint_auth_signing_alg : self . token_endpoint_auth_signing_alg ,
146
+ initiate_login_uri : self . initiate_login_uri ,
147
+ contacts : None ,
148
+ software_id : None ,
149
+ software_version : None ,
150
+ sector_identifier_uri : None ,
151
+ subject_type : None ,
152
+ id_token_encrypted_response_alg : None ,
153
+ id_token_encrypted_response_enc : None ,
154
+ userinfo_encrypted_response_alg : None ,
155
+ userinfo_encrypted_response_enc : None ,
156
+ request_object_signing_alg : None ,
157
+ request_object_encryption_alg : None ,
158
+ request_object_encryption_enc : None ,
159
+ default_max_age : None ,
160
+ require_auth_time : None ,
161
+ default_acr_values : None ,
162
+ request_uris : None ,
163
+ require_signed_request_object : None ,
164
+ require_pushed_authorization_requests : None ,
165
+ introspection_signed_response_alg : None ,
166
+ introspection_encrypted_response_alg : None ,
167
+ introspection_encrypted_response_enc : None ,
168
+ post_logout_redirect_uris : None ,
169
+ }
170
+ }
171
+
126
172
#[ doc( hidden) ]
127
173
pub fn samples ( now : DateTime < Utc > , rng : & mut impl RngCore ) -> Vec < Client > {
128
174
vec ! [
@@ -136,7 +182,6 @@ impl Client {
136
182
Url :: parse( "https://client1.example.com/redirect" ) . unwrap( ) ,
137
183
Url :: parse( "https://client1.example.com/redirect2" ) . unwrap( ) ,
138
184
] ,
139
- response_types: vec![ OAuthAuthorizationEndpointResponseType :: Code ] ,
140
185
grant_types: vec![ GrantType :: AuthorizationCode , GrantType :: RefreshToken ] ,
141
186
client_name: Some ( "Client 1" . to_owned( ) ) ,
142
187
client_uri: Some ( Url :: parse( "https://client1.example.com" ) . unwrap( ) ) ,
@@ -159,7 +204,6 @@ impl Client {
159
204
encrypted_client_secret: None ,
160
205
application_type: Some ( ApplicationType :: Native ) ,
161
206
redirect_uris: vec![ Url :: parse( "https://client2.example.com/redirect" ) . unwrap( ) ] ,
162
- response_types: vec![ OAuthAuthorizationEndpointResponseType :: Code ] ,
163
207
grant_types: vec![ GrantType :: AuthorizationCode , GrantType :: RefreshToken ] ,
164
208
client_name: None ,
165
209
client_uri: None ,
0 commit comments