三方账号授权登录(OAuth2 + userinfo 字段映射 + state 存 Redis)。加平台只需实现 Provider 接口的两个方法;配置不全即不注册,等同「不支持」。
关键导出
Provider interface{ OAuth2Config(cfg); FetchUser(ctx, cfg, client, tok) (*AuthUser, error) }(加平台只须实现两方法)AuthUser struct{UUID, Source, Username, ..., Token AuthToken}Init()按配置注册配置齐全的平台(须在redis.Init之后)GetAuthorizeURL(ctx, source) (string, error)/LoginAuth(ctx, source, code, state) (*AuthUser, error)- 平台标识
SourceGitee / SourceGithub / SourceMaxkey / SourceTopiam ErrUnsupportedSource
典型用法
go
// internal/auth/handler/auth_handler.go:94
url, err := social.GetAuthorizeURL(c.Request.Context(), source)
authUser, err := social.LoginAuth(ctx, body.Source, body.SocialCode, body.SocialState)坑/约定
WARNING
- 配置不全即不注册(等同「不支持」)。
state是裸 UUID,前端原样回传, 不做Base64(JSON)解码(那是 RuoYi-Cloud-Plus 配 vben5 的,不可混用)。httpTimeout=10s防三方网关挂死。tokenFrom从oauth2.Token.Extra取scope/id_token。 :::
相关页:/modules/auth、/pkg-reference/config-database-redis、/pkg-reference/satoken。