@@ -6,6 +6,7 @@ use std::{future::Future, pin::Pin, str::FromStr, sync::Arc};
66
77use crate :: webserver:: http_client:: get_http_client_from_appdata;
88use crate :: { app_config:: AppConfig , AppState } ;
9+ use actix_web:: http:: header;
910use actix_web:: {
1011 body:: BoxBody ,
1112 cookie:: Cookie ,
@@ -520,7 +521,7 @@ async fn build_auth_provider_redirect_response(
520521 let nonce_cookie = create_nonce_cookie ( & params. nonce ) ;
521522 let redirect_cookie = create_redirect_cookie ( & params. csrf_token , initial_url) ;
522523 HttpResponse :: TemporaryRedirect ( )
523- . append_header ( ( "Location" , url. to_string ( ) ) )
524+ . append_header ( ( header :: LOCATION , url. to_string ( ) ) )
524525 . cookie ( nonce_cookie)
525526 . cookie ( redirect_cookie)
526527 . body ( "Redirecting..." )
@@ -794,58 +795,35 @@ fn nonce_matches(id_token_nonce: &Nonce, state_nonce: &Nonce) -> Result<(), Stri
794795 Ok ( ( ) )
795796}
796797
797- #[ derive( Debug , Serialize , Deserialize ) ]
798- struct OidcNonceState {
799- #[ serde( rename = "n" ) ]
800- nonce : Nonce ,
801- }
802-
803- #[ derive( Debug , Serialize , Deserialize ) ]
804- struct OidcRedirectState {
805- #[ serde( rename = "u" ) ]
806- initial_url : String ,
807- }
808-
809798fn create_nonce_cookie ( nonce : & Nonce ) -> Cookie < ' _ > {
810- let nonce_state = OidcNonceState {
811- nonce : nonce. clone ( ) ,
812- } ;
813- let nonce_json = serde_json:: to_string ( & nonce_state) . unwrap ( ) ;
814- Cookie :: build ( SQLPAGE_NONCE_COOKIE_NAME , nonce_json)
799+ Cookie :: build ( SQLPAGE_NONCE_COOKIE_NAME , nonce. secret ( ) )
815800 . secure ( true )
816801 . http_only ( true )
817802 . same_site ( actix_web:: cookie:: SameSite :: Lax )
818803 . path ( "/" )
819- . max_age ( actix_web:: cookie:: time:: Duration :: minutes ( 10 ) )
820804 . finish ( )
821805}
822806
823- fn create_redirect_cookie ( csrf_token : & CsrfToken , initial_url : & str ) -> Cookie < ' static > {
824- let redirect_state = OidcRedirectState {
825- initial_url : initial_url. to_string ( ) ,
826- } ;
827- let redirect_json = serde_json:: to_string ( & redirect_state) . unwrap ( ) ;
807+ fn create_redirect_cookie < ' a > ( csrf_token : & CsrfToken , initial_url : & ' a str ) -> Cookie < ' a > {
828808 let cookie_name = format ! (
829809 "{}{}" ,
830810 SQLPAGE_REDIRECT_URL_COOKIE_PREFIX ,
831811 csrf_token. secret( )
832812 ) ;
833- Cookie :: build ( cookie_name, redirect_json )
813+ Cookie :: build ( cookie_name, initial_url )
834814 . secure ( true )
835815 . http_only ( true )
836816 . same_site ( actix_web:: cookie:: SameSite :: Lax )
837817 . path ( "/" )
838- . max_age ( actix_web:: cookie:: time:: Duration :: minutes ( 5 ) )
818+ . max_age ( actix_web:: cookie:: time:: Duration :: minutes ( 10 ) )
839819 . finish ( )
840820}
841821
842822fn get_nonce_from_cookie ( request : & ServiceRequest ) -> anyhow:: Result < Nonce > {
843823 let cookie = request
844824 . cookie ( SQLPAGE_NONCE_COOKIE_NAME )
845825 . with_context ( || format ! ( "No {SQLPAGE_NONCE_COOKIE_NAME} cookie found" ) ) ?;
846- let nonce_state: OidcNonceState = serde_json:: from_str ( cookie. value ( ) )
847- . with_context ( || format ! ( "Failed to parse nonce from cookie: {cookie}" ) ) ?;
848- Ok ( nonce_state. nonce )
826+ Ok ( Nonce :: new ( cookie. value ( ) . to_string ( ) ) )
849827}
850828
851829fn get_redirect_url_cookie (
0 commit comments