Documentation
¶
Index ¶
- Constants
- Variables
- func AccessCheck(c *gin.Context) error
- func AccessGenerateToken(cid, uid string, nano int64, genRefresh bool) (access, refresh string)
- func AuthorizeGenerateToken(cid, uid string) (code string)
- func CheckClientValidator(form url.Values) int
- func CheckScope(s, s1 string) []string
- func CreateIfNotExist(author *model.Authorize) (bool, *model.Authorize)
- func DefaultDB() *gorm.DB
- func DefaultRedisStrore() *sessions.RedisStore
- func DefaultRouter() *gin.Engine
- func FinishAuthorize(c *gin.Context, u interface{}) (code string, e error)
- func GetAccessTokenAndRefreshToken(client *model.Client, user *model.User) (acc, ref string)
- func GetError(code int) error
- func GetInfo(scope []string, user *model.User, author *model.Authorize) map[string]string
- func GetRedis() redis.Conn
- func GetRefreshToken(c *gin.Context)
- func GetTitleFromClient(client *model.Client) string
- func Home(e *gin.Engine) *gin.RouterGroup
- func NewRedis() *redisx.ConnMux
- func NewRedisStore() *sessions.RedisStore
- func ParseClient(form string) *model.Client
- func ParseClientUser(c *gin.Context) string
- func ParseURL(c *gin.Context, path string) *url.URL
- func PasswordToken(c *gin.Context)
- func PullForm(s *Session) string
- func RawUrl(s string, form url.Values) *url.URL
- func RefreshCheck()
- func ResponseError(c *gin.Context, code int)
- func SignCheck(c *gin.Context)
- func Start()
- func Token(c *gin.Context)
- func ValidatePhone(c *gin.Context, s *Session) bool
- func ValidateUser(c *gin.Context, s *Session) bool
- func VisitLog(c *gin.Context)
- type ErrorResponse
- type Oauth2Server
- type ResponseMessage
- type Session
- type UserAuthorizeInfo
Constants ¶
View Source
const ( E_INVALID_REQUEST = iota //"invalid_request" E_UNAUTHORIZED_CLIENT //"unauthorized_client" E_ACCESS_DENIED //"access_denied" E_UNSUPPORTED_RESPONSE_TYPE //"unsupported_response_type" E_INVALID_SCOPE //"invalid_scope" E_SERVER_ERROR //"server_error" E_TEMPORARILY_UNAVAILABLE //"temporarily_unavailable" E_UNSUPPORTED_GRANT_TYPE //"unsupported_grant_type" E_INVALID_GRANT //"invalid_grant" E_INVALID_CLIENT //"invalid_client" /*----------------------------------------------------*/ E_INVALID_NONE //no errors )
View Source
const DefaultClientName = "玛娜花园"
View Source
const HOST = "http://localhost:7788"
View Source
const TOKEN_PREFIX = "TK_"
Variables ¶
View Source
var ( //登录 A_LOGIN_SUCCESS = ResponseMessage{strconv.Itoa(0), "登陆成功!", nil} A_NAME_OR_PASSWORD_CANNOT_NULL = ResponseMessage{strconv.Itoa(1), "用户名或密码不能为空!", nil} A_MOBILE_OR_CODE_CANNOT_NULL = ResponseMessage{strconv.Itoa(2), "手机或验证码不能为空!", nil} A_NAME_OR_PASSWORD_WRONG = ResponseMessage{strconv.Itoa(3), "用户名或密码错误!", nil} A_COMPLETE_USERINFO_SUCCESS = ResponseMessage{strconv.Itoa(4), "成功完善用户信息!!!", nil} //注册 A_REGISTER_SUCCESS = ResponseMessage{strconv.Itoa(0), "注册成功!", nil} A_MUST_NOT_BE_NULL = ResponseMessage{strconv.Itoa(1), "必填字段不能为空!", nil} A_NAME_FORMAT_WRONG = ResponseMessage{strconv.Itoa(2), "用户名格式错误!", nil} A_NAME_IS_EXISTS = ResponseMessage{strconv.Itoa(3), "用户名已经存在!", nil} A_NAME_LENGTH_WRONG = ResponseMessage{strconv.Itoa(4), "用户名不能少于六位!", nil} A_MOBILE_LENGTH_WRONG = ResponseMessage{strconv.Itoa(5), "手机号填写错误!", nil} A_MOBILE_IS_EXISTS = ResponseMessage{strconv.Itoa(3), "手机号已经被注册!", nil} A_MESSAGE_WRONG = ResponseMessage{strconv.Itoa(6), "手机号验证码错误!", nil} A_PASSWORD_LENGTH_WRONG = ResponseMessage{strconv.Itoa(7), "密码不能少于六位!", nil} A_PASSWORD_COMPARE_WRONG = ResponseMessage{strconv.Itoa(8), "两次密码输入不一致!", nil} // A_MESSAGE_SEND_SUCCESS = ResponseMessage{strconv.Itoa(0), "信息发送成功!", nil} A_MESSAGE_SEND_FAILED = ResponseMessage{strconv.Itoa(1), "信息发送失败!", nil} A_MESSAGE_CHECK_SUCCESS = ResponseMessage{strconv.Itoa(0), "验证码正确!", nil} A_MESSAGE_CHECK_FAILED = ResponseMessage{strconv.Itoa(1), "验证码错误!", nil} A_FORGET_CHECK_SUCCESS = ResponseMessage{strconv.Itoa(0), "验证通过!", nil} A_FORGET_CHANGE_SUCCESS = ResponseMessage{strconv.Itoa(0), "密码变更成功!", nil} A_FORGET_NEED_IS_NULL = ResponseMessage{strconv.Itoa(1), "缺少必填字段!!", nil} A_FORGET_ACCOUNT_WRONG = ResponseMessage{strconv.Itoa(2), "账户填写错误!!", nil} A_FORGET_PASSWORD_CANNOT_NULL = ResponseMessage{strconv.Itoa(3), "密码不能为空!", nil} A_FORGET_PASSWORD_FILL_OUT = ResponseMessage{strconv.Itoa(4), "输入密码不一致!", nil} A_FORGET_SYSTEM_ERROR = ResponseMessage{strconv.Itoa(5), "系统错误,请重试!", nil} //修改密码 A_CHANGE_SUCCESS = ResponseMessage{strconv.Itoa(0), "密码修改成功!", nil} A_CHANGE_NEED_IS_NULL = ResponseMessage{strconv.Itoa(1), "缺少必填字段!!", nil} A_CHANGE_OPASSWORD_WRONG = ResponseMessage{strconv.Itoa(2), "原密码错误!", nil} A_CHANGE_NPASSWORD_FILL_OUT = ResponseMessage{strconv.Itoa(3), "新输入密码不一致!", nil} )
View Source
var ( AuthorizationCodeGrant = "authorization_code" PasswordCredentialsGrant = "password" ClientCredentialsGrant = "client_credentials" RefreshToken = "refresh_token" )
View Source
var ERROR_MAP = map[int]error{ E_INVALID_REQUEST: errors.New("The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed."), E_UNAUTHORIZED_CLIENT: errors.New("The client is not authorized to request a token using this method."), E_ACCESS_DENIED: errors.New("The resource owner or authorization server denied the request."), E_UNSUPPORTED_RESPONSE_TYPE: errors.New("The authorization server does not support obtaining a token using this method."), E_INVALID_SCOPE: errors.New("The requested scope is invalid, unknown, or malformed."), E_SERVER_ERROR: errors.New("The authorization server encountered an unexpected condition that prevented it from fulfilling the request."), E_TEMPORARILY_UNAVAILABLE: errors.New("The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server."), E_UNSUPPORTED_GRANT_TYPE: errors.New("The authorization grant type is not supported by the authorization server."), E_INVALID_GRANT: errors.New("The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."), E_INVALID_CLIENT: errors.New("Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method)."), E_INVALID_NONE: nil, }
Functions ¶
func AccessCheck ¶
func AccessGenerateToken ¶
func AuthorizeGenerateToken ¶
func CheckClientValidator ¶
func CheckScope ¶
func DefaultRedisStrore ¶
func DefaultRedisStrore() *sessions.RedisStore
func DefaultRouter ¶
func GetAccessTokenAndRefreshToken ¶
validate: client_id Required. The client application's id. client_secret Required. The client application's client secret . grant_type Required. Must be set to authorization_code . code Required. The authorization code received by the authorization server. redirect_uri Required, if the request URI was included in the authorization request. Must be identical then.
func GetTitleFromClient ¶
func NewRedisStore ¶
func NewRedisStore() *sessions.RedisStore
func ParseClient ¶
func ParseClientUser ¶
func PasswordToken ¶
func RefreshCheck ¶
func RefreshCheck()
func ResponseError ¶
Types ¶
type ErrorResponse ¶
AuthorizationErrorResponse
type Oauth2Server ¶
type Oauth2Server struct {
// contains filtered or unexported fields
}
func DefaultOauth2Server ¶
func DefaultOauth2Server() *Oauth2Server
func (*Oauth2Server) GetDB ¶
func (gs *Oauth2Server) GetDB() *gorm.DB
func (*Oauth2Server) GetRedisStrore ¶
func (gs *Oauth2Server) GetRedisStrore() *sessions.RedisStore
func (*Oauth2Server) GetRouter ¶
func (gs *Oauth2Server) GetRouter() *gin.Engine
func (*Oauth2Server) Router ¶
func (gs *Oauth2Server) Router()
func (*Oauth2Server) Run ¶
func (gs *Oauth2Server) Run(addr string)
type ResponseMessage ¶
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func AutoDefaultSession ¶
type UserAuthorizeInfo ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.