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.
 
 

30 lines
980 B

package oauth2
import (
"github.com/go-oauth2/oauth2/v4"
"github.com/go-oauth2/oauth2/v4/manage"
"github.com/go-oauth2/oauth2/v4/server"
)
var (
manager *manage.Manager
srv *server.Server
)
func Init() {
manager = manage.NewDefaultManager()
manager.SetValidateURIHandler(nil)
//manager.MustTokenStorage()
manager.MapClientStorage(&ClientStore{})
srv = server.NewServer(server.NewConfig(), manager)
srv.SetClientInfoHandler(nil)
srv.SetAllowedGrantType(oauth2.AuthorizationCode)
// authorization code 模式, 第一步获取code,然后再用code换取 access token, 而不是直接获取 access token
srv.SetAllowedResponseType(oauth2.Code)
// 校验授权请求用户的handler, 会重定向到 登陆页面, 返回"", nil
srv.SetUserAuthorizationHandler(nil)
// 校验授权请求的用户的账号密码, 给 LoginHandler 使用, 简单起见, 只允许一个用户授权
srv.SetPasswordAuthorizationHandler(nil)
srv.SetAllowGetAccessRequest(true)
}