You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.8 KiB
2.8 KiB
LINGYUN.Abp.OpenIddict.WeChat
介绍
LINGYUN.Abp.OpenIddict.WeChat 是一个基于 OpenIddict 的微信认证扩展模块,支持微信公众平台和微信小程序的认证流程。
功能
-
微信公众平台认证
- 支持公众号授权登录
- 支持自动注册新用户
- 支持跨租户认证
- 支持安全日志记录
-
微信小程序认证
- 支持小程序授权登录
- 支持自动注册新用户
- 支持跨租户认证
- 支持安全日志记录
-
用户管理集成
- 支持微信账号绑定
- 支持账号锁定策略
- 支持失败尝试计数
-
安全日志
- 记录登录尝试
- 记录认证失败
- 记录账号锁定
-
本地化支持
- 集成 ABP 本地化框架
- 支持自定义错误消息
安装
dotnet add package LINGYUN.Abp.OpenIddict.WeChat
使用
-
添加
[DependsOn(typeof(AbpOpenIddictWeChatModule))]到你的模块类。 -
配置 OpenIddict 服务器:
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<OpenIddictServerBuilder>(builder =>
{
// 允许微信认证流程
builder.AllowWeChatFlow();
});
}
- 使用示例:
微信公众平台认证:
POST /connect/token
Content-Type: application/x-www-form-urlencoded
grant_type=wechat_official&
code=021iZ1Ga1TpLOB0dXJIa1Zr6RR1iZ1G7&
scope=openid profile wechat
微信小程序认证:
POST /connect/token
Content-Type: application/x-www-form-urlencoded
grant_type=wechat_mini_program&
code=021iZ1Ga1TpLOB0dXJIa1Zr6RR1iZ1G7&
scope=openid profile wechat
参数
-
code (必填)
- 微信授权码
- 必须是有效的微信授权码
-
scope (可选)
- 请求的权限范围
- 默认包含 openid profile wechat
错误码
- invalid_grant
- GrantTypeInvalid - 不被允许的授权类型
- WeChatTokenInvalid - 微信认证失败
- WeChatCodeNotFound - 微信授权码为空或不存在
- WeChatNotRegister - 用户微信账号未绑定
注意事项
- 必须启用相应的功能(公众平台或小程序授权)
- 必须配置正确的微信应用 ID 和密钥
- 授权码有效期有限
- 多次认证失败可能导致账号锁定
- 所有认证操作都会记录在安全日志中
- 生产环境建议使用 HTTPS