Documentation ¶
Index ¶
- Constants
- Variables
- func AuthCodeCallback(roleName ...string) http.Handler
- func AuthCodeCallbackWrap(next http.Handler) http.Handler
- func AuthMiddleware(redirect bool) func(next http.Handler) http.Handler
- func GetAuthCodeURL(state string) string
- func GetOAuth2Config() *oauth2.Config
- func LoginHandler(w http.ResponseWriter, r *http.Request)
- func SessionLoad(r *http.Request) session.Session
- func SessionSave(sess session.Session, w http.ResponseWriter)
- func SetAdminPath(path string)
- func SetLoginPath(path string)
- func Setup(redirectURL, clientID, clientSecret string, scopes []string)
- func SetupSessionStore(store session.Store)
- func TokenFromContext(ctx context.Context) *oauth2.Token
- func UidFromToken(tok *oauth2.Token) string
- type InfoToken
- type RoleMe
- type Staff
- type User
Constants ¶
View Source
const ( TokenKey ctxKey = iota UserKey )
View Source
const ( SessKeyUser = "user" SessKeyToken = "token" )
Variables ¶
View Source
var ( ErrNoToken = errors.New("oauth2 token not found") ErrNoRole = errors.New("the user not in special roles") AdminPath = "/admin/" LoginPath = "/auth/login" UserFromRequest = auth.UserFromRequest )
View Source
var (
SessionIDCookieName = "_sess"
)
Functions ¶
func AuthCodeCallback ¶ added in v0.8.1
AuthCodeCallback Handler for Check auth with role[s] when auth-code callback
func AuthCodeCallbackWrap ¶
AuthCodeCallbackWrap is a middleware that injects a InfoToken with roles into the context of callback request
func AuthMiddleware ¶ added in v0.8.1
AuthMiddleware
func GetAuthCodeURL ¶
func GetOAuth2Config ¶
func LoginHandler ¶
func LoginHandler(w http.ResponseWriter, r *http.Request)
func SessionSave ¶ added in v0.8.1
func SessionSave(sess session.Session, w http.ResponseWriter)
func SetAdminPath ¶ added in v0.8.1
func SetAdminPath(path string)
func SetLoginPath ¶ added in v0.8.1
func SetLoginPath(path string)
func SetupSessionStore ¶ added in v0.8.1
func TokenFromContext ¶
TokenFromContext returns a oauth2.Token from the given context if one is present. Returns nil if a oauth2.Token cannot be found.
func UidFromToken ¶
UidFromToken extract uid from oauth2.Token
Types ¶
type InfoToken ¶
type InfoToken struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type,omitempty"` RefreshToken string `json:"refresh_token,omitempty"` ExpiresIn int64 `json:"expires_in,omitempty"` Expiry time.Time `json:"expiry,omitempty"` Me Staff `json:"me,omitempty"` Roles RoleMe `json:"group,omitempty"` }
func AuthRequestWithRole ¶ added in v0.8.1
AuthRequestWithRole called in AuthCallback
func RequestInfoToken ¶
type Staff ¶
type Staff struct { UID string `json:"uid" form:"uid"` // 登录名 CommonName string `json:"cn,omitempty" form:"cn"` // 全名 GivenName string `json:"gn,omitempty" form:"gn"` // 名 Surname string `json:"sn,omitempty" form:"sn"` // 姓 Nickname string `json:"nickname,omitempty" form:"nickname"` // 昵称 Birthday string `json:"birthday,omitempty" form:"birthday"` // 生日 Gender common.Gender `json:"gender,omitempty"` // 1=male, 2=female, 0=unknown Mobile string `json:"mobile,omitempty"` // cell phone number Email string `json:"email,omitempty"` EmployeeNumber int `json:"eid,omitempty" form:"eid"` EmployeeType string `json:"etype,omitempty" form:"etitle"` AvatarPath string `json:"avatarPath,omitempty" form:"avatar"` Provider string `json:"provider,omitempty"` }
Staff is a retrieved employee struct.
Click to show internal directories.
Click to hide internal directories.