diff --git a/examples/server/authentication_controller.rs b/examples/server/authentication_controller.rs index 452cc10..4cad61e 100644 --- a/examples/server/authentication_controller.rs +++ b/examples/server/authentication_controller.rs @@ -15,14 +15,17 @@ pub struct OpenIdConfiguration { pub authorization_endpoint: String } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] #[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))] pub struct StartAuthenticationResponse { - #[serde(rename = "authenticationUrl")] - pub authentication_url: String, + #[serde(rename = "authenticationUrl", skip_serializing_if="Option::is_none")] + pub authentication_url: Option, - #[serde(rename = "authenticationRequestId")] - pub authentication_request_id: String + #[serde(rename = "authenticationRequestId", skip_serializing_if="Option::is_none")] + pub authentication_request_id: Option, + + #[serde(rename = "accessToken", skip_serializing_if="Option::is_none")] + pub access_token: Option } #[derive(Debug, Default, Clone, Copy)] @@ -35,13 +38,23 @@ impl AuthenticationController { let access_token = signature_key.create_token(host); let id_token = signature_key.create_id_token(host); - let url = Url::parse_with_params(&authentication_request.redirect_url, - &[("access_token", &access_token), ("id_token", &id_token), ("nonce", &request_id.to_string())] - ).unwrap(); + if let Some(redirect_url) = authentication_request.redirect_url { + let parsed_url = Url::parse_with_params(&redirect_url, + &[("access_token", &access_token), ("id_token", &id_token), ("nonce", &request_id.to_string())] + ); + if let Ok(url) = parsed_url { + return StartAuthenticationResponse { + authentication_request_id: Some(request_id.to_string()), + authentication_url: Some(url.to_string()), + access_token: Some(access_token) + } + } + } return StartAuthenticationResponse { - authentication_request_id: request_id.to_string(), - authentication_url: url.to_string() + authentication_request_id: None, + authentication_url: None, + access_token: Some(access_token) } } diff --git a/src/authentication/mod.rs b/src/authentication/mod.rs index ba42b0e..bb246bb 100644 --- a/src/authentication/mod.rs +++ b/src/authentication/mod.rs @@ -61,7 +61,7 @@ pub enum AuthenticationResponse { #[derive(Default, Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct AuthenticationRequest { #[serde(rename = "redirectUrl")] - pub redirect_url: String, + pub redirect_url: Option, // /// The secret associated with the client that authorizes the generation of token it's behalf. (Either the `client_secret` or the `code_verifier` is required) // #[serde(rename = "client_secret", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] // pub client_secret: Option>, @@ -81,18 +81,3 @@ pub struct AuthenticationRequest { // #[serde(rename = "type", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] // pub r#type: Option>, } - -impl AuthenticationRequest { - pub fn new(redirect_url: String) -> AuthenticationRequest { - AuthenticationRequest { - redirect_url, - // client_id, - // client_secret: None, - // code_verifier: None, - // grant_type: None, - // username: None, - // password: None, - // r#type: None, - } - } -} \ No newline at end of file