@@ -113,9 +113,6 @@ pub(crate) enum RouteError {
113113 expected : UpstreamOAuthProviderResponseMode ,
114114 } ,
115115
116- #[ error( "Invalid request method '{method}'" ) ]
117- InvalidReqMethod { method : Method } ,
118-
119116 #[ error( transparent) ]
120117 Internal ( Box < dyn std:: error:: Error + Send + Sync + ' static > ) ,
121118}
@@ -187,46 +184,26 @@ pub(crate) async fn handler(
187184 // The `Form` extractor will use the body of the request for POST requests and
188185 // the query parameters for GET requests. We need to then look at the method do
189186 // make sure it matches the expected `response_mode`
190- match method {
191- Method :: GET => {
192- match provider. response_mode {
193- Some ( UpstreamOAuthProviderResponseMode :: Query ) | None => { }
194- Some ( UpstreamOAuthProviderResponseMode :: FormPost ) => {
195- return Err ( RouteError :: InvalidResponseMode {
196- expected : UpstreamOAuthProviderResponseMode :: Query ,
197- } )
198- }
199- } ;
200- }
201- Method :: POST => {
202- match provider. response_mode {
203- Some ( UpstreamOAuthProviderResponseMode :: FormPost ) => {
204- // We set the cookies with a `Same-Site` policy set to `Lax`, so because this is
205- // usually a cross-site form POST, we need to render a form with the
206- // same values, which posts back to the same URL. However, there are
207- // other valid reasons for the cookie to be missing, so to track whether we did
208- // this POST ourselves, we set a flag.
209- if sessions_cookie. is_empty ( ) && !params. did_mas_repost_to_itself {
210- let params = Params {
211- did_mas_repost_to_itself : true ,
212- ..params
213- } ;
214- let context =
215- FormPostContext :: new_for_current_url ( params) . with_language ( & locale) ;
216- let html = templates. render_form_post ( & context) ?;
217- return Ok ( Html ( html) . into_response ( ) ) ;
218- }
219- }
220- Some ( UpstreamOAuthProviderResponseMode :: Query ) | None => {
221- return Err ( RouteError :: InvalidResponseMode {
222- expected : UpstreamOAuthProviderResponseMode :: FormPost ,
223- } )
224- }
225- } ;
226- }
227- method => {
228- return Err ( RouteError :: InvalidReqMethod { method } ) ;
187+ match ( provider. response_mode , method) {
188+ ( Some ( UpstreamOAuthProviderResponseMode :: Query ) | None , Method :: GET ) => { }
189+ ( Some ( UpstreamOAuthProviderResponseMode :: FormPost ) | None , Method :: POST ) => {
190+ // We set the cookies with a `Same-Site` policy set to `Lax`, so because this is
191+ // usually a cross-site form POST, we need to render a form with the
192+ // same values, which posts back to the same URL. However, there are
193+ // other valid reasons for the cookie to be missing, so to track whether we did
194+ // this POST ourselves, we set a flag.
195+ if sessions_cookie. is_empty ( ) && !params. did_mas_repost_to_itself {
196+ let params = Params {
197+ did_mas_repost_to_itself : true ,
198+ ..params
199+ } ;
200+ let context = FormPostContext :: new_for_current_url ( params) . with_language ( & locale) ;
201+ let html = templates. render_form_post ( & context) ?;
202+ return Ok ( Html ( html) . into_response ( ) ) ;
203+ }
229204 }
205+ ( None , _) => { }
206+ ( Some ( expected) , _) => return Err ( RouteError :: InvalidResponseMode { expected } ) ,
230207 }
231208
232209 let ( session_id, _post_auth_action) = sessions_cookie
0 commit comments