feat(auth): 小程序登录采集微信昵称
This commit is contained in:
@@ -796,7 +796,7 @@ impl WechatProvider {
|
||||
) -> Result<WechatIdentityProfile, WechatProviderError> {
|
||||
match self {
|
||||
Self::Disabled => Err(WechatProviderError::Disabled),
|
||||
Self::Mock(provider) => Ok(provider.resolve_callback_profile(code)),
|
||||
Self::Mock(provider) => Ok(provider.resolve_mini_program_login_profile(code)),
|
||||
Self::Real(provider) => provider.resolve_mini_program_login_profile(code).await,
|
||||
}
|
||||
}
|
||||
@@ -839,6 +839,21 @@ impl MockWechatProvider {
|
||||
session_key: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_mini_program_login_profile(&self, mock_code: Option<&str>) -> WechatIdentityProfile {
|
||||
let provider_uid = mock_code
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.unwrap_or(self.mock_user_id.as_str())
|
||||
.to_string();
|
||||
WechatIdentityProfile {
|
||||
provider_uid: provider_uid.clone(),
|
||||
provider_union_id: self.mock_union_id.clone(),
|
||||
display_name: None,
|
||||
avatar_url: None,
|
||||
session_key: Some(format!("mock-session-key-{provider_uid}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RealWechatProvider {
|
||||
@@ -2274,6 +2289,42 @@ mod tests {
|
||||
assert_eq!(profile.display_name.as_deref(), Some("微信测试用户"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn mock_wechat_provider_resolves_mini_program_profile_without_nickname() {
|
||||
let provider = WechatProvider::new(WechatAuthConfig::new(
|
||||
true,
|
||||
"mock".to_string(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
DEFAULT_WECHAT_AUTHORIZE_ENDPOINT.to_string(),
|
||||
DEFAULT_WECHAT_ACCESS_TOKEN_ENDPOINT.to_string(),
|
||||
DEFAULT_WECHAT_USER_INFO_ENDPOINT.to_string(),
|
||||
DEFAULT_WECHAT_JS_CODE_SESSION_ENDPOINT.to_string(),
|
||||
DEFAULT_WECHAT_STABLE_ACCESS_TOKEN_ENDPOINT.to_string(),
|
||||
DEFAULT_WECHAT_PHONE_NUMBER_ENDPOINT.to_string(),
|
||||
"wx-user-001".to_string(),
|
||||
Some("wx-union-001".to_string()),
|
||||
"微信测试用户".to_string(),
|
||||
Some("https://example.test/avatar.png".to_string()),
|
||||
));
|
||||
|
||||
let profile = provider
|
||||
.resolve_mini_program_login_profile(Some("wx-mini-code-001"))
|
||||
.await
|
||||
.expect("mock mini program profile should resolve");
|
||||
|
||||
assert_eq!(profile.provider_uid, "wx-mini-code-001");
|
||||
assert_eq!(profile.provider_union_id.as_deref(), Some("wx-union-001"));
|
||||
assert_eq!(profile.display_name, None);
|
||||
assert_eq!(profile.avatar_url, None);
|
||||
assert_eq!(
|
||||
profile.session_key.as_deref(),
|
||||
Some("mock-session-key-wx-mini-code-001")
|
||||
);
|
||||
}
|
||||
|
||||
fn build_jwt_config() -> JwtConfig {
|
||||
JwtConfig::new(
|
||||
"https://auth.genarrative.local".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user