Documentation
¶
Overview ¶
Example ¶
This example create a identify middleware instance and attach to several path, it will validate request by specified policy and put extra information into context. e.g., `mid`. It provides additional handler functions to provide the identification for your business handler.
package main
import (
"fmt"
"github.com/iwhile/kratos/example/blademaster/middleware/auth"
bm "github.com/iwhile/kratos/pkg/net/http/blademaster"
"github.com/iwhile/kratos/pkg/net/metadata"
)
func main() {
myHandler := func(ctx *bm.Context) {
mid := metadata.Int64(ctx, metadata.Mid)
ctx.JSON(fmt.Sprintf("%d", mid), nil)
}
authn := auth.New(&auth.Config{
DisableCSRF: false,
})
e := bm.DefaultServer(nil)
// mark `/user` path as User policy
e.GET("/user", authn.User, myHandler)
// mark `/mobile` path as UserMobile policy
e.GET("/mobile", authn.UserMobile, myHandler)
// mark `/web` path as UserWeb policy
e.GET("/web", authn.UserWeb, myHandler)
// mark `/guest` path as Guest policy
e.GET("/guest", authn.Guest, myHandler)
o := e.Group("/owner", authn.User)
o.GET("/info", myHandler)
o.POST("/modify", myHandler)
e.Start()
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth is the authorization middleware
func (*Auth) Guest ¶
Guest is used to mark path as guest policy. If `access_token` is exist in request form, it will using mobile access policy. Otherwise to web access policy.
func (*Auth) GuestMobile ¶
GuestMobile is used to mark path as mobile guest policy.
func (*Auth) User ¶
User is used to mark path as access required. If `access_token` is exist in request form, it will using mobile access policy. Otherwise to web access policy.
func (*Auth) UserMobile ¶
UserMobile is used to mark path as mobile access required.