Documentation ¶
Overview ¶
Package oauth 提供基于 OAuth2 的登录和注册功能
## 大致流程
- 前端访问 authURL
- 三方返回前端的 callback 页面
- callback 提交 {username: 'vendor id', password: 'code'}
- 后端的登录页调用 Authenticator.Valid 验证验录,如果未注册则自动注册;
- 登录页返回 token 给 callback 页,由该页面决定如何处理;
Index ¶
Constants ¶
View Source
const ( TwitterAuthURL = "https://api.twitter.com/2/oauth2/authorize" TwitterTokenURL = "https://api.twitter.com/2/oauth2/token" )
Variables ¶
View Source
var TwitterScopes = []string{"tweet.read", "users.read"}
Functions ¶
Types ¶
type OAuth ¶
type OAuth[T UserInfo] struct { // contains filtered or unexported fields }
OAuth 表示 oauth2 登录的验证器
func New ¶
func New[T UserInfo](s *web.Server, prefix orm.Prefix, db *orm.DB, c *oauth2.Config, g GetUserInfoFunc[T]) *OAuth[T]
New 声明 OAuth 对象
r 表示注册用户的方法,如果为 nil,那么碰到为未注册的用户时,OAuth.Valid 直接返回 false, 否则的话将尝试注册了新用户并返回新用户的 id。 prefix 表名前缀,当有多个不同实例时,prefix 不能相同。
type TwitterUserInfo ¶
func TwitterGetUserInfo ¶
func TwitterGetUserInfo(token *oauth2.Token) (*TwitterUserInfo, error)
func (*TwitterUserInfo) Identity ¶
func (info *TwitterUserInfo) Identity() string
Click to show internal directories.
Click to hide internal directories.