todo一律大写

This commit is contained in:
李运家 2024-10-30 20:18:39 +08:00
parent a01536771e
commit 200e9e0e88
4 changed files with 8 additions and 51 deletions

View File

@ -24,7 +24,7 @@ pub struct GoogleSocial {
// 假设GOOGLE_PUBLIC_CERT_URL是Google提供的公钥URL // 假设GOOGLE_PUBLIC_CERT_URL是Google提供的公钥URL
const GOOGLE_PUBLIC_CERT_URL: &str = "https://www.googleapis.com/oauth2/v3/certs"; const GOOGLE_PUBLIC_CERT_URL: &str = "https://www.googleapis.com/oauth2/v3/certs";
#[derive(Debug, Default)] #[derive(Debug, Default, Deserialize)]
pub struct GoogleJwtProfile { pub struct GoogleJwtProfile {
// iss (issuer):签发人 // iss (issuer):签发人
pub iss: String, pub iss: String,
@ -48,6 +48,7 @@ pub struct GoogleJwtProfile {
} }
impl GoogleJwtProfile { impl GoogleJwtProfile {
#[allow(unused)]
fn new() -> Self { fn new() -> Self {
GoogleJwtProfile { GoogleJwtProfile {
..Default::default() ..Default::default()
@ -57,49 +58,7 @@ impl GoogleJwtProfile {
impl From<Value> for GoogleJwtProfile { impl From<Value> for GoogleJwtProfile {
fn from(value: Value) -> Self { fn from(value: Value) -> Self {
let mut google_jwt_profile = GoogleJwtProfile::new(); let google_jwt_profile: GoogleJwtProfile = serde_json::from_value(value).expect("解析GoogleJwtProfile json失败");
if let Some(value) = value.get("iss") {
google_jwt_profile.iss = value.as_str().unwrap().to_string();
}
if let Some(value) = value.get("sub") {
google_jwt_profile.sub = value.as_str().unwrap().to_string();
}
if let Some(value) = value.get("azp") {
google_jwt_profile.azp = value.as_str().unwrap().to_string();
}
if let Some(value) = value.get("aud") {
google_jwt_profile.aud = value.as_str().unwrap().to_string();
}
if let Some(value) = value.get("iat") {
google_jwt_profile.iat = value.as_i64().unwrap_or_default();
}
if let Some(value) = value.get("exp") {
google_jwt_profile.exp = value.as_i64().unwrap_or_default();
}
if let Some(value) = value.get("email") {
google_jwt_profile.email = value.as_str().unwrap().to_string();
}
if let Some(value) = value.get("email_verified") {
google_jwt_profile.email_verified = value.as_bool().unwrap_or_default();
}
if let Some(value) = value.get("at_hash") {
google_jwt_profile.at_hash = value.as_str().unwrap().to_string();
}
if let Some(value) = value.get("name") {
google_jwt_profile.name = value.as_str().unwrap().to_string();
}
if let Some(value) = value.get("picture") {
google_jwt_profile.picture = value.as_str().unwrap().to_string();
}
if let Some(value) = value.get("given_name") {
google_jwt_profile.given_name = value.as_str().unwrap().to_string();
}
if let Some(value) = value.get("family_name") {
google_jwt_profile.family_name = value.as_str().unwrap().to_string();
}
if let Some(value) = value.get("locale") {
google_jwt_profile.locale = value.as_str().unwrap().to_string();
}
google_jwt_profile google_jwt_profile
} }
} }
@ -167,9 +126,7 @@ impl GoogleSocial {
let kid = kid.unwrap(); let kid = kid.unwrap();
// 根据kid找到正确的公钥 // 根据kid找到正确的公钥
let key = public_keys let key = public_keys.get(&kid).ok_or_else(|| Box::new(ResErr::social("校验Token失败,未找到正确的公钥")))?;
.get(&kid)
.ok_or_else(|| Box::new(ResErr::social("校验Token失败,未找到正确的公钥")))?;
tracing::debug!("public key : {:?}", key); tracing::debug!("public key : {:?}", key);
// TODO: // TODO:

View File

@ -162,7 +162,7 @@ impl WechatSocial {
/// ///
/// https://developers.weixin.qq.com/minigame/dev/api-backend/open-api/login/auth.checkSessionKey.html /// https://developers.weixin.qq.com/minigame/dev/api-backend/open-api/login/auth.checkSessionKey.html
/// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/checkSessionKey.html /// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/checkSessionKey.html
/// todo 使用的hmac签名是否正确签名结果转换成字符串是否正确目前未经验证 /// TODO 使用的hmac签名是否正确签名结果转换成字符串是否正确目前未经验证
pub async fn check_session(&self, session_key: &str, open_id: &str) -> SocialResult<()> { pub async fn check_session(&self, session_key: &str, open_id: &str) -> SocialResult<()> {
let token = self.get_access_token().await?; let token = self.get_access_token().await?;
let mut mac = let mut mac =

View File

@ -12,7 +12,7 @@ pub async fn get_wechat_access_token(context: Context) -> ResResult<WeChatAccess
/// 微信用户登录code通过wx.login获取 /// 微信用户登录code通过wx.login获取
/// ///
/// todo 登录成功后,判断用户是否存在,不存在,则注册用户,存在,则更新用户信息 /// TODO 登录成功后,判断用户是否存在,不存在,则注册用户,存在,则更新用户信息
#[post("/wechat/code_2_session")] #[post("/wechat/code_2_session")]
pub async fn code_2_session( pub async fn code_2_session(
context: Context, context: Context,

View File

@ -24,7 +24,7 @@ pub async fn get_wechat_access_token(context: Context) -> ResResult<WeChatAccess
/// 微信登录code通过wx.login获取 /// 微信登录code通过wx.login获取
/// ///
/// todo 登录成功后,判断用户是否存在,不存在,则注册用户,存在,则更新用户信息 /// TODO 登录成功后,判断用户是否存在,不存在,则注册用户,存在,则更新用户信息
pub async fn code_2_session(context: Context, code: String) -> ResResult<MiniAppLoginResult> { pub async fn code_2_session(context: Context, code: String) -> ResResult<MiniAppLoginResult> {
let lang_tag = context.get_lang_tag(); let lang_tag = context.get_lang_tag();
let result = match WECHAT_SOCIAL.code_2_session(&code).await { let result = match WECHAT_SOCIAL.code_2_session(&code).await {
@ -42,7 +42,7 @@ pub async fn code_2_session(context: Context, code: String) -> ResResult<MiniApp
/// 微信登录校验 /// 微信登录校验
/// ///
/// todo 校验成功后,判断用户是否存在 /// TODO 校验成功后,判断用户是否存在
pub async fn check_session(context: Context, wx_login_info: WxLoginInfo) -> ResResult<()> { pub async fn check_session(context: Context, wx_login_info: WxLoginInfo) -> ResResult<()> {
let lang_tag = context.get_lang_tag(); let lang_tag = context.get_lang_tag();
let session_key = wx_login_info.session_key.unwrap(); let session_key = wx_login_info.session_key.unwrap();