@ -65,43 +65,43 @@ async fn login(
let login_result = match data . grant_type . as_ref ( ) {
let login_result = match data . grant_type . as_ref ( ) {
"refresh_token" = > {
"refresh_token" = > {
_check_is_some ( & data . refresh_token , "refresh_token cannot be blank" ) ? ;
_check_is_some ( data . refresh_token . as_ref ( ) , "refresh_token cannot be blank" ) ? ;
_refresh_login ( data , & conn , & client_header . ip ) . await
_refresh_login ( data , & conn , & client_header . ip ) . await
}
}
"password" if CONFIG . sso_enabled ( ) & & CONFIG . sso_only ( ) = > err ! ( "SSO sign-in is required" ) ,
"password" if CONFIG . sso_enabled ( ) & & CONFIG . sso_only ( ) = > err ! ( "SSO sign-in is required" ) ,
"password" = > {
"password" = > {
_check_is_some ( & data . client_id , "client_id cannot be blank" ) ? ;
_check_is_some ( data . client_id . as_ref ( ) , "client_id cannot be blank" ) ? ;
_check_is_some ( & data . password , "password cannot be blank" ) ? ;
_check_is_some ( data . password . as_ref ( ) , "password cannot be blank" ) ? ;
_check_is_some ( & data . scope , "scope cannot be blank" ) ? ;
_check_is_some ( data . scope . as_ref ( ) , "scope cannot be blank" ) ? ;
_check_is_some ( & data . username , "username cannot be blank" ) ? ;
_check_is_some ( data . username . as_ref ( ) , "username cannot be blank" ) ? ;
_check_is_some ( & data . device_identifier , "device_identifier cannot be blank" ) ? ;
_check_is_some ( data . device_identifier . as_ref ( ) , "device_identifier cannot be blank" ) ? ;
_check_is_some ( & data . device_name , "device_name cannot be blank" ) ? ;
_check_is_some ( data . device_name . as_ref ( ) , "device_name cannot be blank" ) ? ;
_check_is_some ( & data . device_type , "device_type cannot be blank" ) ? ;
_check_is_some ( data . device_type . as_ref ( ) , "device_type cannot be blank" ) ? ;
_password_login ( data , & mut user_id , & conn , & client_header . ip , & client_version ) . await
_password_login ( data , & mut user_id , & conn , & client_header . ip , client_version . as_ref ( ) ) . await
}
}
"client_credentials" = > {
"client_credentials" = > {
_check_is_some ( & data . client_id , "client_id cannot be blank" ) ? ;
_check_is_some ( data . client_id . as_ref ( ) , "client_id cannot be blank" ) ? ;
_check_is_some ( & data . client_secret , "client_secret cannot be blank" ) ? ;
_check_is_some ( data . client_secret . as_ref ( ) , "client_secret cannot be blank" ) ? ;
_check_is_some ( & data . scope , "scope cannot be blank" ) ? ;
_check_is_some ( data . scope . as_ref ( ) , "scope cannot be blank" ) ? ;
_check_is_some ( & data . device_identifier , "device_identifier cannot be blank" ) ? ;
_check_is_some ( data . device_identifier . as_ref ( ) , "device_identifier cannot be blank" ) ? ;
_check_is_some ( & data . device_name , "device_name cannot be blank" ) ? ;
_check_is_some ( data . device_name . as_ref ( ) , "device_name cannot be blank" ) ? ;
_check_is_some ( & data . device_type , "device_type cannot be blank" ) ? ;
_check_is_some ( data . device_type . as_ref ( ) , "device_type cannot be blank" ) ? ;
_api_key_login ( data , & mut user_id , & conn , & client_header . ip ) . await
_api_key_login ( data , & mut user_id , & conn , & client_header . ip ) . await
}
}
"authorization_code" if CONFIG . sso_enabled ( ) = > {
"authorization_code" if CONFIG . sso_enabled ( ) = > {
_check_is_some ( & data . client_id , "client_id cannot be blank" ) ? ;
_check_is_some ( data . client_id . as_ref ( ) , "client_id cannot be blank" ) ? ;
_check_is_some ( & data . code , "code cannot be blank" ) ? ;
_check_is_some ( data . code . as_ref ( ) , "code cannot be blank" ) ? ;
_check_is_some ( & data . code_verifier , "code verifier cannot be blank" ) ? ;
_check_is_some ( data . code_verifier . as_ref ( ) , "code verifier cannot be blank" ) ? ;
_check_is_some ( & data . device_identifier , "device_identifier cannot be blank" ) ? ;
_check_is_some ( data . device_identifier . as_ref ( ) , "device_identifier cannot be blank" ) ? ;
_check_is_some ( & data . device_name , "device_name cannot be blank" ) ? ;
_check_is_some ( data . device_name . as_ref ( ) , "device_name cannot be blank" ) ? ;
_check_is_some ( & data . device_type , "device_type cannot be blank" ) ? ;
_check_is_some ( data . device_type . as_ref ( ) , "device_type cannot be blank" ) ? ;
_sso_login ( data , & mut user_id , & conn , & client_header . ip , & client_version ) . await
_sso_login ( data , & mut user_id , & conn , & client_header . ip , client_version . as_ref ( ) ) . await
}
}
"authorization_code" = > err ! ( "SSO sign-in is not available" ) ,
"authorization_code" = > err ! ( "SSO sign-in is not available" ) ,
t = > err ! ( "Invalid type" , t ) ,
t = > err ! ( "Invalid type" , t ) ,
@ -177,7 +177,7 @@ async fn _sso_login(
user_id : & mut Option < UserId > ,
user_id : & mut Option < UserId > ,
conn : & DbConn ,
conn : & DbConn ,
ip : & ClientIp ,
ip : & ClientIp ,
client_version : & Option < ClientVersion > ,
client_version : Option < & ClientVersion > ,
) -> JsonResult {
) -> JsonResult {
AuthMethod ::Sso . check_scope ( data . scope . as_ref ( ) ) ? ;
AuthMethod ::Sso . check_scope ( data . scope . as_ref ( ) ) ? ;
@ -320,7 +320,7 @@ async fn _password_login(
user_id : & mut Option < UserId > ,
user_id : & mut Option < UserId > ,
conn : & DbConn ,
conn : & DbConn ,
ip : & ClientIp ,
ip : & ClientIp ,
client_version : & Option < ClientVersion > ,
client_version : Option < & ClientVersion > ,
) -> JsonResult {
) -> JsonResult {
// Validate scope
// Validate scope
AuthMethod ::Password . check_scope ( data . scope . as_ref ( ) ) ? ;
AuthMethod ::Password . check_scope ( data . scope . as_ref ( ) ) ? ;
@ -734,7 +734,7 @@ async fn twofactor_auth(
data : & ConnectData ,
data : & ConnectData ,
device : & mut Device ,
device : & mut Device ,
ip : & ClientIp ,
ip : & ClientIp ,
client_version : & Option < ClientVersion > ,
client_version : Option < & ClientVersion > ,
conn : & DbConn ,
conn : & DbConn ,
) -> ApiResult < Option < String > > {
) -> ApiResult < Option < String > > {
let twofactors = TwoFactor ::find_by_user ( & user . uuid , conn ) . await ;
let twofactors = TwoFactor ::find_by_user ( & user . uuid , conn ) . await ;
@ -879,7 +879,7 @@ async fn _json_err_twofactor(
providers : & [ i32 ] ,
providers : & [ i32 ] ,
user_id : & UserId ,
user_id : & UserId ,
data : & ConnectData ,
data : & ConnectData ,
client_version : & Option < ClientVersion > ,
client_version : Option < & ClientVersion > ,
conn : & DbConn ,
conn : & DbConn ,
) -> ApiResult < Value > {
) -> ApiResult < Value > {
let mut result = json ! ( {
let mut result = json ! ( {
@ -1114,7 +1114,7 @@ struct ConnectData {
#[ field(name = uncased( " code_verifier " )) ]
#[ field(name = uncased( " code_verifier " )) ]
code_verifier : Option < OIDCCodeVerifier > ,
code_verifier : Option < OIDCCodeVerifier > ,
}
}
fn _check_is_some < T > ( value : & Option < T > , msg : & str ) -> EmptyResult {
fn _check_is_some < T > ( value : Option < & T > , msg : & str ) -> EmptyResult {
if value . is_none ( ) {
if value . is_none ( ) {
err ! ( msg )
err ! ( msg )
}
}