chore: add and fix hanldlers to use openid with casdoor for Single Sign-On
This commit is contained in:
parent
97a411bdc8
commit
3faeffda66
@ -71,7 +71,6 @@ pub fn users_router_handlers() -> Router {
|
||||
// // TODO check value
|
||||
// }
|
||||
//let has_cookie: bool;
|
||||
// dbg!(&auth_state.session);
|
||||
// if auth_state.user.is_none() {
|
||||
// eprintln!("No user found in session");
|
||||
// }
|
||||
@ -97,7 +96,6 @@ pub fn users_router_handlers() -> Router {
|
||||
// println!("Auth State from root");
|
||||
// }
|
||||
// let uri_path = format!("{}",&uri.path().to_string());
|
||||
// dbg!("uri: {}",&uri_path);
|
||||
req_handler.prepare_response();
|
||||
req_handler.context.insert("with_menu", "1");
|
||||
let result = if let Some(tpl) = app_dbs.config.tpls.get("main") {
|
||||
@ -183,7 +181,6 @@ pub fn users_router_handlers() -> Router {
|
||||
// cookies.add(cookie);
|
||||
// }
|
||||
// */
|
||||
// dbg!("uri: {}",&uri_path);
|
||||
// (
|
||||
// header,
|
||||
// result.to_owned()
|
||||
@ -501,9 +498,6 @@ pub fn users_router_handlers() -> Router {
|
||||
ConnectInfo(app_connect_info): ConnectInfo<AppConnectInfo>,
|
||||
axum::extract::Path(data): axum::extract::Path<String>,
|
||||
) -> Response {
|
||||
dbg!(&header);
|
||||
dbg!(&uri);
|
||||
dbg!(&data);
|
||||
SessionStoreDB::cleanup_data(&app_dbs).await;
|
||||
let auth_state = get_auth_state(true, &cookies, &app_dbs).await;
|
||||
let req_handler = ReqHandler::new(
|
||||
@ -528,7 +522,6 @@ pub fn users_router_handlers() -> Router {
|
||||
}
|
||||
let (str_user_data,url) = if let Some(openid_conf) = app_dbs.config.openid_auths.get(&data) {
|
||||
if let Some(openid_cli) = openid_clients.get(&data) {
|
||||
dbg!(&openid_conf);
|
||||
match openid_conf.get_auth(openid_cli).await {
|
||||
Ok(openid) => {
|
||||
//let _ = req_handler.trace_req(format!("User '{}' created",&user_data.name));
|
||||
@ -559,7 +552,6 @@ pub fn users_router_handlers() -> Router {
|
||||
(String::from(""), String::from("/login"))
|
||||
};
|
||||
let session_token = req_handler.new_token();
|
||||
dbg!(&url);
|
||||
let session_cookie = add_session_cookie(true,&cookies, &session_token, &str_user_data, 0, &app_dbs, "/").await;
|
||||
if app_dbs.config.verbose > 1 { println!("session cookie: {}", &session_cookie) };
|
||||
let _new_auth_state = AuthState::from_cookie(session_cookie.to_string(), &app_dbs).await;
|
||||
@ -585,7 +577,6 @@ pub fn users_router_handlers() -> Router {
|
||||
&random,
|
||||
"post_login_handler"
|
||||
);
|
||||
dbg!(&user_login);
|
||||
if user_login.name.is_empty() || source != "from_login_openid" && user_login.password.is_empty() {
|
||||
let _ = req_handler.trace_req(String::from("Empty name or password"));
|
||||
// return Err(error_page(&SignupError::MissingDetails));
|
||||
@ -595,8 +586,6 @@ pub fn users_router_handlers() -> Router {
|
||||
"Error"
|
||||
).into_response();
|
||||
}
|
||||
dbg!(&user_login);
|
||||
dbg!(&source);
|
||||
let field = if user_login.name.contains("@") {
|
||||
"email"
|
||||
} else {
|
||||
@ -606,7 +595,6 @@ pub fn users_router_handlers() -> Router {
|
||||
println!("Error select: {}", e);
|
||||
User::default()
|
||||
});
|
||||
dbg!(&user_sel);
|
||||
if user_sel.name.is_empty() {
|
||||
let _ = req_handler.trace_req(format!("No name '{}' found",&user_login.name));
|
||||
// User not exists
|
||||
@ -616,7 +604,6 @@ pub fn users_router_handlers() -> Router {
|
||||
"Error data"
|
||||
).into_response();
|
||||
}
|
||||
dbg!(&user_sel);
|
||||
if user_sel.status != UserStatus::Active && user_sel.status != UserStatus::Created {
|
||||
let _ = req_handler.trace_req(format!("user '{}' in not valid status: {}",&user_login.name, &user_sel.status));
|
||||
return (
|
||||
@ -625,7 +612,6 @@ pub fn users_router_handlers() -> Router {
|
||||
"Error status"
|
||||
).into_response();
|
||||
}
|
||||
dbg!(&user_sel);
|
||||
let result = if source == "from_login_openid" {
|
||||
format!("{}:true", "OK")
|
||||
} else {
|
||||
@ -763,10 +749,8 @@ pub fn users_router_handlers() -> Router {
|
||||
let mut user_login = UserLogin::default();
|
||||
if let Some(openid_conf) = app_dbs.config.openid_auths.get(&user_data[0]) {
|
||||
if let Some(openid_cli) = openid_clients.get(&user_data[0]) {
|
||||
dbg!(openid_conf);
|
||||
match openid_conf.get_token(openid_cli, data.code.to_owned(), user_data[2].to_owned()).await {
|
||||
Ok(data) => {
|
||||
dbg!("{}", &data);
|
||||
user_login = UserLogin {
|
||||
name: data.name.to_owned(),
|
||||
password: String::from(""),
|
||||
@ -901,7 +885,6 @@ pub fn users_router_handlers() -> Router {
|
||||
// String::from("")
|
||||
// });
|
||||
// req_handler.context.insert("with_menu", "1");
|
||||
// dbg!("uri: {}",&uri_path);
|
||||
// // let mut new_header = header.to_owned();
|
||||
// //new_header.append("Set-Cookie", "session_token=_; Max-Age=0".parse().unwrap());
|
||||
// // cookies.remove(Cookie::new(SESSION_COOKIE_NAME, ""));
|
||||
@ -1376,7 +1359,6 @@ pub fn users_router_handlers() -> Router {
|
||||
// Query(req_params): Query<ReqParams>,
|
||||
axum::extract::Path(data): axum::extract::Path<String>,
|
||||
) -> Response {
|
||||
// dbg!(&user_item);
|
||||
let session_cookie = decode(&data).unwrap_or_default().to_string();
|
||||
let auth_state = AuthState::from_cookie(session_cookie.to_owned(), &app_dbs).await;
|
||||
let mut req_handler = ReqHandler::new(
|
||||
@ -1610,7 +1592,6 @@ pub fn users_router_handlers() -> Router {
|
||||
ConnectInfo(app_connect_info): ConnectInfo<AppConnectInfo>,
|
||||
Json(user_invite): Json<UserInvitation>,
|
||||
) -> Response {
|
||||
//dbg!(&user_item);
|
||||
let auth_state = get_auth_state(true, &cookies, &app_dbs).await;
|
||||
let mut req_handler = ReqHandler::new(
|
||||
ReqHeaderMap::new(header, &format!("{}",&uri.path().to_string()), &app_connect_info),
|
||||
@ -1817,7 +1798,6 @@ pub fn users_router_handlers() -> Router {
|
||||
// println!("Error render {}: {}",&file,e);
|
||||
// String::from("")
|
||||
// });
|
||||
//dbg!("uri: {}",&uri_path);
|
||||
// let mut new_header = header.to_owned();
|
||||
//new_header.append("Set-Cookie", "session_token=_; Max-Age=0".parse().unwrap());
|
||||
// cookies.remove(Cookie::new(SESSION_COOKIE_NAME, ""));
|
||||
@ -1838,7 +1818,6 @@ pub fn users_router_handlers() -> Router {
|
||||
//_auth_state: AuthState,
|
||||
//axum::extract::Path(data): axum::extract::Path<String>,
|
||||
) -> Response {
|
||||
dbg!(&user_item);
|
||||
let auth_state = get_auth_state(true, &cookies, &app_dbs).await;
|
||||
let req_handler = ReqHandler::new(
|
||||
ReqHeaderMap::new(header, &format!("{}",&uri.path().to_string()), &app_connect_info),
|
||||
@ -1857,6 +1836,7 @@ pub fn users_router_handlers() -> Router {
|
||||
// "Error authorization"
|
||||
// ).into_response();
|
||||
}
|
||||
dbg!("{}",&user_item);
|
||||
let result="";
|
||||
(
|
||||
//status,
|
||||
|
Loading…
Reference in New Issue
Block a user