-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
66 lines (59 loc) · 2.13 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
_ "oauthServer/docs"
"oauthServer/handler"
"oauthServer/pkg/ginConfig"
"oauthServer/pkg/ginServer"
)
// @title Swagger API
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]
//////@license.name Apache 2.0
/////@license.url http://www.apache.org/licenses/LICENSE-2.0.html
///// @host petstore.swagger.io
///// @BasePath /
func main() {
ginServer.Default()
g := ginConfig.Default()
url := ginSwagger.URL("http://localhost:8000/swagger/doc.json") // The url pointing to API definition
g.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
// wolf-rbac插件 适配apisix网关的接口
wolf := g.Group("/wolf/rbac")
{
//核心接口,apisix核心鉴权能力
wolf.GET("/access_check", handler.AccessCheckHandler)
//登陆调用 可以不实现,如果不实现则无法使用插件对应的login
wolf.POST("/login.rest", func(c *gin.Context) {
ginServer.HandleTokenRequest(c)
})
//获取用户信息 可以不实现,如果不实现则无法使用插件对应的user_info
wolf.GET("/user_info", func(c *gin.Context) {
})
//wolf.GET("/logout",)
}
// 标准oauth2 端点可以不实现
auth := g.Group("/oauth2")
{
//token 生成端点,注意:token生成端点创建的token不会销毁之前的token
auth.GET("/token_endpoint", ginServer.HandleTokenRequest)
auth.POST("/token_endpoint", ginServer.HandleTokenRequest)
//token authorization认证端点
auth.GET("/authorization_endpoint", ginServer.HandleAuthorizeRequest)
auth.POST("/authorization_endpoint", ginServer.HandleAuthorizeRequest)
//校验token
auth.GET("/check_token", ginServer.ValidationBearerToken)
auth.POST("/check_token", ginServer.ValidationBearerToken)
}
// Listen and Server in 0.0.0.0:8080
if err := g.Run(":8000"); err != nil {
log.Fatal().Msg("无法从 8000 端口启动服务")
}
}