1616//! capabilities and configuration, including supported signing algorithms and endpoints.
1717
1818use base64:: Engine ;
19- use rocket:: serde:: json:: { Json , Value , json } ;
19+ use rocket:: serde:: json:: { json , Json , Value } ;
2020use rocket:: { get, State } ;
2121use serde:: { Deserialize , Serialize } ;
2222
23- use crate :: visualization:: jwt_keys:: JwkKeySet ;
2423use super :: oxide_auth:: OxideState ;
24+ use crate :: visualization:: jwt_keys:: JwkKeySet ;
2525
2626/// OpenID Connect Discovery Configuration
2727///
@@ -32,34 +32,34 @@ use super::oxide_auth::OxideState;
3232pub struct OpenIdConfiguration {
3333 /// URL using the https scheme with no query or fragment component that the OP asserts as its Issuer Identifier
3434 pub issuer : String ,
35-
35+
3636 /// URL of the OP's OAuth 2.0 Authorization Endpoint
3737 pub authorization_endpoint : String ,
38-
38+
3939 /// URL of the OP's OAuth 2.0 Token Endpoint
4040 pub token_endpoint : String ,
41-
41+
4242 /// URL of the OP's JSON Web Key Set document
4343 pub jwks_uri : String ,
44-
44+
4545 /// JSON array containing a list of the OAuth 2.0 response_type values that this server supports
4646 pub response_types_supported : Vec < String > ,
47-
47+
4848 /// JSON array containing a list of the OAuth 2.0 Grant Type values that this server supports
4949 pub grant_types_supported : Vec < String > ,
50-
50+
5151 /// JSON array containing a list of the Subject Identifier types that this server supports
5252 pub subject_types_supported : Vec < String > ,
53-
53+
5454 /// JSON array containing a list of the JWS signing algorithms supported by this server for the ID Token
5555 pub id_token_signing_alg_values_supported : Vec < String > ,
56-
56+
5757 /// JSON array containing a list of the JWS algorithms that this server supports for the UserInfo Endpoint
5858 pub userinfo_signing_alg_values_supported : Vec < String > ,
59-
59+
6060 /// JSON array containing the scopes that this server supports
6161 pub scopes_supported : Vec < String > ,
62-
62+
6363 /// JSON array containing a list of the claim names of the Claims that the OpenID Provider supports
6464 pub claims_supported : Vec < String > ,
6565}
@@ -81,20 +81,26 @@ pub struct OpenIdConfiguration {
8181fn generate_openid_configuration ( base_url : & str , state : & OxideState ) -> OpenIdConfiguration {
8282 // Determine which signing algorithms are supported
8383 let mut signing_algs = vec ! [ "HS256" . to_string( ) ] ;
84-
84+
8585 // If we have RS256 keys configured, add RS256
8686 log:: debug!( "RS256 public key length: {}" , state. rs256_public_key. len( ) ) ;
87- log:: debug!( "RS256 private key length: {}" , state. rs256_private_key. len( ) ) ;
88-
87+ log:: debug!(
88+ "RS256 private key length: {}" ,
89+ state. rs256_private_key. len( )
90+ ) ;
91+
8992 if !state. rs256_public_key . is_empty ( ) && !state. rs256_private_key . is_empty ( ) {
9093 // Add RS256 if we have keys, regardless of whether decoding succeeds
9194 signing_algs. push ( "RS256" . to_string ( ) ) ;
9295 log:: debug!( "RS256 signing algorithm added to OpenID configuration" ) ;
9396 } else {
94- log:: warn!( "RS256 keys are not properly configured - public key empty: {}, private key empty: {}" ,
95- state. rs256_public_key. is_empty( ) , state. rs256_private_key. is_empty( ) ) ;
97+ log:: warn!(
98+ "RS256 keys are not properly configured - public key empty: {}, private key empty: {}" ,
99+ state. rs256_public_key. is_empty( ) ,
100+ state. rs256_private_key. is_empty( )
101+ ) ;
96102 }
97-
103+
98104 OpenIdConfiguration {
99105 issuer : base_url. to_string ( ) ,
100106 authorization_endpoint : format ! ( "{}/authorize" , base_url) ,
@@ -149,10 +155,10 @@ pub async fn openid_configuration(state: &State<OxideState>) -> Json<OpenIdConfi
149155 // In a production environment, you would want to get the base URL from the request
150156 // or configuration. For simplicity, we're using a hardcoded value here.
151157 let base_url = "http://localhost:8080" ;
152-
158+
153159 // Generate the configuration document
154160 let config = generate_openid_configuration ( base_url, state) ;
155-
161+
156162 Json ( config)
157163}
158164
@@ -164,9 +170,9 @@ pub async fn openid_configuration(state: &State<OxideState>) -> Json<OpenIdConfi
164170/// issued by this server.
165171///
166172/// # URL
167- ///
168- ///
169- ///
173+ ///
174+ ///
175+ ///
170176///
171177/// `GET /.well-known/jwks.json`
172178///
@@ -177,17 +183,19 @@ pub async fn openid_configuration(state: &State<OxideState>) -> Json<OpenIdConfi
177183pub async fn jwks ( state : & State < OxideState > ) -> Json < Value > {
178184 // Create a key set for our public keys
179185 let mut keys = vec ! [ ] ;
180-
186+
181187 // If we have an RS256 public key, add it to the key set
182- if let Ok ( rs256_pub_key) = base64:: engine:: general_purpose:: STANDARD . decode ( & state. rs256_public_key ) {
188+ if let Ok ( rs256_pub_key) =
189+ base64:: engine:: general_purpose:: STANDARD . decode ( & state. rs256_public_key )
190+ {
183191 if !rs256_pub_key. is_empty ( ) {
184192 // Parse the PEM encoded public key
185193 if let Ok ( jwk) = JwkKeySet :: create_jwk_from_pem ( & rs256_pub_key) {
186194 keys. push ( jwk) ;
187195 }
188196 }
189197 }
190-
198+
191199 // Return the key set
192200 Json ( json ! ( {
193201 "keys" : keys
0 commit comments