更新依赖项,优化 OAuth2 服务,添加 PKCE 支持,增强 OIDC 处理器,新增客户端注册和令牌管理端点,改进数据库模型以支持新功能。
This commit is contained in:
21
main.go
21
main.go
@@ -35,7 +35,12 @@ func main() {
|
||||
|
||||
// 初始化服务
|
||||
authService := services.NewAuthService(db)
|
||||
oauthService := services.NewOAuthService(db, []byte(config.GlobalConfig.JWT.SigningKey))
|
||||
oauthService, err := services.NewOAuthService(db)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to initialize OAuth service: %v", err)
|
||||
}
|
||||
clientService := services.NewClientService(db)
|
||||
tokenService := services.NewTokenService(db, oauthService.GetKeyManager())
|
||||
|
||||
// 设置 Gin 路由
|
||||
r := gin.Default()
|
||||
@@ -44,7 +49,7 @@ func main() {
|
||||
r.LoadHTMLGlob("templates/*")
|
||||
|
||||
// 设置 session 中间件
|
||||
store := cookie.NewStore([]byte("secret"))
|
||||
store := cookie.NewStore([]byte(config.GlobalConfig.JWT.SigningKey))
|
||||
r.Use(sessions.Sessions("oidc_session", store))
|
||||
|
||||
// 健康检查
|
||||
@@ -57,6 +62,8 @@ func main() {
|
||||
// 创建处理器
|
||||
authHandler := handlers.NewAuthHandler(authService)
|
||||
oidcHandler := handlers.NewOIDCHandler(config.GlobalConfig.OAuth.IssuerURL, oauthService, authService)
|
||||
registrationHandler := handlers.NewRegistrationHandler(clientService)
|
||||
tokenHandler := handlers.NewTokenHandler(tokenService)
|
||||
|
||||
// 认证路由
|
||||
r.GET("/login", authHandler.ShowLogin)
|
||||
@@ -69,6 +76,16 @@ func main() {
|
||||
r.GET("/userinfo", oidcHandler.Userinfo)
|
||||
r.GET("/jwks", oidcHandler.JWKS)
|
||||
|
||||
// 客户端注册端点
|
||||
r.POST("/register", registrationHandler.Register)
|
||||
r.GET("/register/:client_id", registrationHandler.GetClient)
|
||||
r.PUT("/register/:client_id", registrationHandler.UpdateClient)
|
||||
r.DELETE("/register/:client_id", registrationHandler.DeleteClient)
|
||||
|
||||
// 令牌管理端点
|
||||
r.POST("/revoke", tokenHandler.Revoke)
|
||||
r.POST("/introspect", tokenHandler.Introspect)
|
||||
|
||||
// 启动服务器
|
||||
addr := fmt.Sprintf("%s:%d", config.GlobalConfig.Server.Host, config.GlobalConfig.Server.Port)
|
||||
log.Printf("Starting server on %s", addr)
|
||||
|
||||
Reference in New Issue
Block a user