mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-06-08 02:12:49 +08:00
fix oidc login
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
b9fd9f343f
commit
c28387c8c6
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -5250,6 +5250,7 @@ dependencies = [
|
|||||||
"serde 1.0.163",
|
"serde 1.0.163",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json 1.0.96",
|
"serde_json 1.0.96",
|
||||||
|
"serde_repr",
|
||||||
"sha2",
|
"sha2",
|
||||||
"shared_memory",
|
"shared_memory",
|
||||||
"shutdown_hooks",
|
"shutdown_hooks",
|
||||||
|
@ -43,6 +43,7 @@ hbb_common = { path = "libs/hbb_common" }
|
|||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
serde_repr = "0.1"
|
||||||
cfg-if = "1.0"
|
cfg-if = "1.0"
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
|
@ -95,11 +95,13 @@ class ConfigOP {
|
|||||||
class WidgetOP extends StatefulWidget {
|
class WidgetOP extends StatefulWidget {
|
||||||
final ConfigOP config;
|
final ConfigOP config;
|
||||||
final RxString curOP;
|
final RxString curOP;
|
||||||
|
final RxBool autoLogin;
|
||||||
final Function(String) cbLogin;
|
final Function(String) cbLogin;
|
||||||
const WidgetOP({
|
const WidgetOP({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.config,
|
required this.config,
|
||||||
required this.curOP,
|
required this.curOP,
|
||||||
|
required this.autoLogin,
|
||||||
required this.cbLogin,
|
required this.cbLogin,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@ -188,7 +190,7 @@ class _WidgetOPState extends State<WidgetOP> {
|
|||||||
onTap: () async {
|
onTap: () async {
|
||||||
_resetState();
|
_resetState();
|
||||||
widget.curOP.value = widget.config.op;
|
widget.curOP.value = widget.config.op;
|
||||||
await bind.mainAccountAuth(op: widget.config.op);
|
await bind.mainAccountAuth(op: widget.config.op, rememberMe: widget.autoLogin.value);
|
||||||
_beginQueryState();
|
_beginQueryState();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -254,12 +256,14 @@ class _WidgetOPState extends State<WidgetOP> {
|
|||||||
class LoginWidgetOP extends StatelessWidget {
|
class LoginWidgetOP extends StatelessWidget {
|
||||||
final List<ConfigOP> ops;
|
final List<ConfigOP> ops;
|
||||||
final RxString curOP;
|
final RxString curOP;
|
||||||
|
final RxBool autoLogin;
|
||||||
final Function(String) cbLogin;
|
final Function(String) cbLogin;
|
||||||
|
|
||||||
LoginWidgetOP({
|
LoginWidgetOP({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.ops,
|
required this.ops,
|
||||||
required this.curOP,
|
required this.curOP,
|
||||||
|
required this.autoLogin,
|
||||||
required this.cbLogin,
|
required this.cbLogin,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@ -270,6 +274,7 @@ class LoginWidgetOP extends StatelessWidget {
|
|||||||
WidgetOP(
|
WidgetOP(
|
||||||
config: op,
|
config: op,
|
||||||
curOP: curOP,
|
curOP: curOP,
|
||||||
|
autoLogin: autoLogin,
|
||||||
cbLogin: cbLogin,
|
cbLogin: cbLogin,
|
||||||
),
|
),
|
||||||
const Divider(
|
const Divider(
|
||||||
@ -500,6 +505,7 @@ Future<bool?> loginDialog() async {
|
|||||||
ConfigOP(op: 'Okta', iconWidth: 38),
|
ConfigOP(op: 'Okta', iconWidth: 38),
|
||||||
],
|
],
|
||||||
curOP: curOP,
|
curOP: curOP,
|
||||||
|
autoLogin: autoLogin,
|
||||||
cbLogin: (String username) {
|
cbLogin: (String username) {
|
||||||
gFFI.userModel.userName.value = username;
|
gFFI.userModel.userName.value = username;
|
||||||
close(true);
|
close(true);
|
||||||
|
@ -1359,10 +1359,10 @@ pub fn install_install_path() -> SyncReturn<String> {
|
|||||||
SyncReturn(install_path())
|
SyncReturn(install_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main_account_auth(op: String) {
|
pub fn main_account_auth(op: String, remember_me: bool) {
|
||||||
let id = get_id();
|
let id = get_id();
|
||||||
let uuid = get_uuid();
|
let uuid = get_uuid();
|
||||||
account_auth(op, id, uuid);
|
account_auth(op, id, uuid, remember_me);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main_account_auth_cancel() {
|
pub fn main_account_auth_cancel() {
|
||||||
|
@ -5,6 +5,7 @@ use hbb_common::{
|
|||||||
};
|
};
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
@ -30,21 +31,80 @@ pub struct OidcAuthUrl {
|
|||||||
url: Url,
|
url: Url,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||||
|
pub struct DeviceInfo {
|
||||||
|
/// Linux , Windows , Android ...
|
||||||
|
#[serde(default)]
|
||||||
|
pub os: String,
|
||||||
|
|
||||||
|
/// `browser` or `client`
|
||||||
|
#[serde(default)]
|
||||||
|
pub r#type: String,
|
||||||
|
|
||||||
|
/// device name from rustdesk client,
|
||||||
|
/// browser info(name + version) from browser
|
||||||
|
#[serde(default)]
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct WhitelistItem {
|
||||||
|
data: String, // ip / device uuid
|
||||||
|
info: DeviceInfo,
|
||||||
|
exp: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct UserInfo {
|
||||||
|
#[serde(default)]
|
||||||
|
pub settings: UserSettings,
|
||||||
|
#[serde(default)]
|
||||||
|
pub login_ip_whitelist: Vec<WhitelistItem>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub login_device_whitelist: Vec<WhitelistItem>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub other: HashMap<String, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct UserSettings {
|
||||||
|
#[serde(default)]
|
||||||
|
pub email_verification: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub email_alarm_notification: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Serialize_repr, Deserialize_repr)]
|
||||||
|
#[repr(i64)]
|
||||||
|
pub enum UserStatus {
|
||||||
|
Disabled = 0,
|
||||||
|
Normal = 1,
|
||||||
|
Unverified = -1,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Serialize_repr, Deserialize_repr)]
|
||||||
|
#[repr(i64)]
|
||||||
|
pub enum UserRole {
|
||||||
|
Owner = 10,
|
||||||
|
Admin = 1,
|
||||||
|
Member = 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct UserPayload {
|
pub struct UserPayload {
|
||||||
pub id: String,
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub email: Option<String>,
|
pub email: Option<String>,
|
||||||
pub note: Option<String>,
|
pub note: Option<String>,
|
||||||
pub status: Option<i64>,
|
pub status: UserStatus,
|
||||||
pub grp: Option<String>,
|
pub info: UserInfo,
|
||||||
pub is_admin: Option<bool>,
|
pub role: UserRole,
|
||||||
|
pub is_admin: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AuthBody {
|
pub struct AuthBody {
|
||||||
pub access_token: String,
|
pub access_token: String,
|
||||||
pub token_type: String,
|
pub r#type: String,
|
||||||
pub user: UserPayload,
|
pub user: UserPayload,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +188,7 @@ impl OidcSession {
|
|||||||
std::thread::sleep(std::time::Duration::from_secs_f32(secs));
|
std::thread::sleep(std::time::Duration::from_secs_f32(secs));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn auth_task(op: String, id: String, uuid: String) {
|
fn auth_task(op: String, id: String, uuid: String, remember_me: bool) {
|
||||||
let auth_request_res = Self::auth(&op, &id, &uuid);
|
let auth_request_res = Self::auth(&op, &id, &uuid);
|
||||||
log::info!("Request oidc auth result: {:?}", &auth_request_res);
|
log::info!("Request oidc auth result: {:?}", &auth_request_res);
|
||||||
let code_url = match auth_request_res {
|
let code_url = match auth_request_res {
|
||||||
@ -167,14 +227,16 @@ impl OidcSession {
|
|||||||
while OIDC_SESSION.read().unwrap().keep_querying && begin.elapsed() < query_timeout {
|
while OIDC_SESSION.read().unwrap().keep_querying && begin.elapsed() < query_timeout {
|
||||||
match Self::query(&code_url.code, &id, &uuid) {
|
match Self::query(&code_url.code, &id, &uuid) {
|
||||||
Ok(HbbHttpResponse::<_>::Data(auth_body)) => {
|
Ok(HbbHttpResponse::<_>::Data(auth_body)) => {
|
||||||
LocalConfig::set_option(
|
if remember_me {
|
||||||
"access_token".to_owned(),
|
LocalConfig::set_option(
|
||||||
auth_body.access_token.clone(),
|
"access_token".to_owned(),
|
||||||
);
|
auth_body.access_token.clone(),
|
||||||
LocalConfig::set_option(
|
);
|
||||||
"user_info".to_owned(),
|
LocalConfig::set_option(
|
||||||
serde_json::to_string(&auth_body.user).unwrap_or_default(),
|
"user_info".to_owned(),
|
||||||
);
|
serde_json::to_string(&auth_body.user).unwrap_or_default(),
|
||||||
|
);
|
||||||
|
}
|
||||||
OIDC_SESSION
|
OIDC_SESSION
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -226,12 +288,12 @@ impl OidcSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn account_auth(op: String, id: String, uuid: String) {
|
pub fn account_auth(op: String, id: String, uuid: String, remember_me: bool) {
|
||||||
Self::auth_cancel();
|
Self::auth_cancel();
|
||||||
Self::wait_stop_querying();
|
Self::wait_stop_querying();
|
||||||
OIDC_SESSION.write().unwrap().before_task();
|
OIDC_SESSION.write().unwrap().before_task();
|
||||||
std::thread::spawn(|| {
|
std::thread::spawn(move || {
|
||||||
Self::auth_task(op, id, uuid);
|
Self::auth_task(op, id, uuid, remember_me);
|
||||||
OIDC_SESSION.write().unwrap().after_task();
|
OIDC_SESSION.write().unwrap().after_task();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -822,8 +822,8 @@ fn check_connect_status(reconnect: bool) -> mpsc::UnboundedSender<ipc::Data> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "flutter")]
|
#[cfg(feature = "flutter")]
|
||||||
pub fn account_auth(op: String, id: String, uuid: String) {
|
pub fn account_auth(op: String, id: String, uuid: String, remember_me: bool) {
|
||||||
account::OidcSession::account_auth(op, id, uuid);
|
account::OidcSession::account_auth(op, id, uuid, remember_me);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "flutter")]
|
#[cfg(feature = "flutter")]
|
||||||
|
Loading…
Reference in New Issue
Block a user