-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
174 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
APP_ID="app_id" | ||
APP_SECRET="app_secret" | ||
USER_ACCESS_TOKEN="test_user_access_token" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use dotenvy::dotenv; | ||
use std::env; | ||
|
||
use open_lark::client::LarkClient; | ||
|
||
/// 获取登录用户信息 | ||
#[tokio::main] | ||
async fn main() { | ||
dotenv().expect(".env file not found"); | ||
env_logger::init(); | ||
let app_id = env::var("APP_ID").unwrap(); | ||
let app_secret = env::var("APP_SECRET").unwrap(); | ||
let user_access_token = env::var("USER_ACCESS_TOKEN").unwrap(); | ||
// 创建 Client | ||
let client = LarkClient::builder(&app_id, &app_secret).build(); | ||
|
||
// 发起请求 | ||
let resp = client | ||
.auth | ||
.v1 | ||
.user_info | ||
.get(user_access_token) | ||
.await | ||
.unwrap(); | ||
match resp.data.as_ref() { | ||
Some(data) => { | ||
println!("user_info: {:#?}", data); | ||
} | ||
None => { | ||
println!("user_info error: {:#?}", resp); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pub mod v1; | ||
|
||
pub struct AuthenService { | ||
pub v1: v1::V1, | ||
} | ||
|
||
impl AuthenService { | ||
pub fn new(config: crate::core::config::Config) -> Self { | ||
Self { | ||
v1: v1::V1::new(config), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use crate::core::api_req::ApiRequest; | ||
use crate::core::api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat}; | ||
use crate::core::config::Config; | ||
use crate::core::constants::AccessTokenType; | ||
use crate::core::http::Transport; | ||
use crate::core::req_option::RequestOption; | ||
use crate::core::SDKResult; | ||
use serde::Deserialize; | ||
|
||
pub struct UserInfoService { | ||
config: Config, | ||
} | ||
|
||
impl UserInfoService { | ||
pub fn new(config: Config) -> Self { | ||
Self { config } | ||
} | ||
|
||
/// 获取登录用户信息 | ||
pub async fn get(&self, user_access_token: impl ToString) -> SDKResult<BaseResponse<UserInfo>> { | ||
let api_req = ApiRequest { | ||
api_path: "/open-apis/authen/v1/user_info".to_string(), | ||
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User], | ||
..Default::default() | ||
}; | ||
|
||
let option = RequestOption::builder() | ||
.user_access_token(user_access_token) | ||
.build(); | ||
let api_resp = Transport::request(api_req, &self.config, Some(option)).await?; | ||
|
||
Ok(api_resp) | ||
} | ||
} | ||
|
||
/// 登录用户信息 | ||
#[derive(Debug, Deserialize)] | ||
pub struct UserInfo { | ||
/// 用户姓名 | ||
pub name: String, | ||
/// 用户英文名称 | ||
pub en_name: String, | ||
/// 用户头像 | ||
pub avatar_url: String, | ||
/// 用户头像 72x72 | ||
pub avatar_thumb: String, | ||
/// 用户头像 240x240 | ||
pub avatar_middle: String, | ||
/// 用户头像 640x640 | ||
pub avatar_big: String, | ||
/// 用户在应用内的唯一标识 | ||
pub open_id: String, | ||
/// 用户对ISV的唯一标识,对于同一个ISV,用户在其名下所有应用的union_id相同 | ||
pub union_id: String, | ||
/// 用户邮箱 | ||
pub email: Option<String>, | ||
/// 企业邮箱,请先确保已在管理后台启用飞书邮箱服务 | ||
pub enterprise_email: Option<String>, | ||
/// 用户 user_id | ||
pub user_id: String, | ||
/// 用户手机号 | ||
pub mobile: Option<String>, | ||
/// 当前企业标识 | ||
pub tenant_key: String, | ||
/// 用户工号 | ||
pub employee_no: String, | ||
} | ||
|
||
impl ApiResponseTrait for UserInfo { | ||
fn data_format() -> ResponseFormat { | ||
ResponseFormat::Data | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_user_info() { | ||
let json_str = r#"{ | ||
"name": "zhangsan", | ||
"en_name": "zhangsan", | ||
"avatar_url": "www.feishu.cn/avatar/icon", | ||
"avatar_thumb": "www.feishu.cn/avatar/icon_thumb", | ||
"avatar_middle": "www.feishu.cn/avatar/icon_middle", | ||
"avatar_big": "www.feishu.cn/avatar/icon_big", | ||
"open_id": "ou-caecc734c2e3328a62489fe0648c4b98779515d3", | ||
"union_id": "on-d89jhsdhjsajkda7828enjdj328ydhhw3u43yjhdj", | ||
"email": "[email protected]", | ||
"enterprise_email": "[email protected]", | ||
"user_id": "5d9bdxxx", | ||
"mobile": "+86130002883xx", | ||
"tenant_key": "736588c92lxf175d", | ||
"employee_no": "111222333" | ||
}"#; | ||
|
||
let user_info: UserInfo = serde_json::from_str(json_str).unwrap(); | ||
|
||
assert_eq!(user_info.name, "zhangsan") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pub use auth::*; | ||
|
||
mod auth; | ||
|
||
pub struct V1 { | ||
/// 身份验证 | ||
pub user_info: UserInfoService, | ||
} | ||
|
||
impl V1 { | ||
pub fn new(config: crate::core::config::Config) -> Self { | ||
Self { | ||
user_info: UserInfoService::new(config), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod authentication; | ||
pub mod bitable; | ||
pub mod drive; | ||
pub mod im; | ||
|