@@ -17,8 +17,8 @@ use crate::{
1717#[ derive( Debug , Deserialize ) ]
1818#[ serde( rename_all = "camelCase" ) ]
1919pub struct SignInData {
20- pub redirect_origin : Option < Url > ,
21- pub redirect_url : Option < Url > ,
20+ pub redirect_origin : Url ,
21+ pub redirect_url : Option < String > ,
2222}
2323
2424pub struct OauthSignInAction {
@@ -91,15 +91,13 @@ impl Action<OauthProvider, OauthSession> for OauthSignInAction {
9191 let data = serde_json:: from_value :: < SignInData > ( request. form_data )
9292 . map_err ( |err| ShieldError :: Validation ( err. to_string ( ) ) ) ?;
9393
94- let redirect_url = data. redirect_url . or_else ( || {
95- data . redirect_origin . and_then ( |redirect_origin| {
96- redirect_origin. join ( & self . options . sign_in_redirect ) . ok ( )
97- } )
98- } ) ;
94+ let redirect_url = data
95+ . redirect_url
96+ . map ( |redirect_url| data . redirect_origin . join ( & redirect_url ) )
97+ . unwrap_or_else ( || data . redirect_origin . join ( & self . options . sign_in_redirect ) )
98+ . map_err ( |err| ShieldError :: Validation ( format ! ( "redirect URL parse error: {err}" ) ) ) ? ;
9999
100- if let Some ( redirect_url) = & redirect_url
101- && let Some ( redirect_origins) = & self . options . redirect_origins
102- {
100+ if let Some ( redirect_origins) = & self . options . redirect_origins {
103101 let redirect_origin = Url :: parse ( & redirect_url. origin ( ) . ascii_serialization ( ) )
104102 . map_err ( |err| {
105103 ShieldError :: Validation ( format ! ( "redirect origin parse error: {err}" ) )
@@ -148,7 +146,7 @@ impl Action<OauthProvider, OauthSession> for OauthSignInAction {
148146 Ok ( Response :: new ( ResponseType :: Redirect ( auth_url. to_string ( ) ) )
149147 . session_action ( SessionAction :: Unauthenticate )
150148 . session_action ( SessionAction :: data ( OauthSession {
151- redirect_url,
149+ redirect_url : Some ( redirect_url ) ,
152150 csrf : Some ( csrf_token. secret ( ) . clone ( ) ) ,
153151 pkce_verifier : pkce_code_challenge
154152 . map ( |( _, pkce_code_verifier) | pkce_code_verifier. secret ( ) . clone ( ) ) ,
0 commit comments