Skip to content

Commit

Permalink
認証方法を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
FlowingSPDG committed Jun 21, 2024
1 parent 5296300 commit 4c81f83
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// Auth Auth interface handles auth
type Auth interface {
EventAuth(ctx context.Context, serverID string, auth string) error
EventAuth(ctx context.Context, auth string) error
MatchAuth(ctx context.Context, mid int, auth string) error
CheckDemoAuth(ctx context.Context, mid int, filename string, mapNumber int, serverID string, auth string) error
}
Expand Down
8 changes: 3 additions & 5 deletions route/gin/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,10 @@ func OnEventHandler(ctrl got5.EventHandler) func(c *gin.Context) {
}

// CheckEventHandlerAuth Check Auth
func CheckEventHandlerAuth(auth got5.Auth) func(c *gin.Context) {
func CheckEventHandlerAuth(auth got5.Auth, headerKey string) func(c *gin.Context) {
return (func(c *gin.Context) {
// NOTICE: get5_remote_log_header_value only supports max 128 characters
reqAuth := c.GetHeader("Authorization")
serverID := c.GetHeader("Get5-ServerId")
if err := auth.EventAuth(c, serverID, reqAuth); err != nil {
headerValue := c.GetHeader(headerKey)
if err := auth.EventAuth(c, headerValue); err != nil {
c.AbortWithError(http.StatusUnauthorized, err) // カスタムエラーを返したい
return
}
Expand Down
6 changes: 3 additions & 3 deletions route/gin/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
)

// CheckMatchLoaderAuth 認証用ハンドラ
func CheckMatchLoaderAuth(auth got5.Auth) func(c *gin.Context) {
func CheckMatchLoaderAuth(auth got5.Auth, headerKey string) func(c *gin.Context) {
return (func(c *gin.Context) {
matchID := c.Param("matchID")
reqAuthVal := c.GetHeader("Authorization")
headerValue := c.GetHeader(headerKey)

mid, err := strconv.Atoi(matchID)
if err != nil {
c.AbortWithError(http.StatusBadRequest, err)
return
}
if err := auth.MatchAuth(c, mid, reqAuthVal); err != nil {
if err := auth.MatchAuth(c, mid, headerValue); err != nil {
c.AbortWithError(http.StatusUnauthorized, err) // カスタムエラーを返したい
return
}
Expand Down
15 changes: 4 additions & 11 deletions route/gin/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@ import (
"github.com/gin-gonic/gin"
)

// SetupAllGet5Handlers Setup All Get5-related handlers
func SetupAllGet5Handlers(evh got5.EventHandler, loader got5.MatchLoader, uploader got5.DemoUploader, auth got5.Auth, r gin.IRoutes) {
SetupEventHandlers(evh, auth, r)
SetupMatchLoadHandler(loader, auth, r)
SetupDemoUploadHandler(uploader, auth, r)
}

// SetupDemoUploadHandler Setup get5 upload demo handler
func SetupDemoUploadHandler(uploader got5.DemoUploader, auth got5.Auth, r gin.IRoutes) {
r.POST("/demo", CheckDemoAuth(auth), DemoUploadHandler(uploader))
}

// SetupMatchLoadHandler Setup get5 loadmatch handler
func SetupMatchLoadHandler(loader got5.MatchLoader, auth got5.Auth, r gin.IRoutes) {
r.GET("/match/:matchID", CheckMatchLoaderAuth(auth), LoadMatchHandler(loader))
func SetupMatchLoadHandler(loader got5.MatchLoader, auth got5.Auth, authHeaderkey string, r gin.IRoutes) {
r.GET("/match/:matchID", CheckMatchLoaderAuth(auth, authHeaderkey), LoadMatchHandler(loader))
}

// SetupEventHandlers get5 handlers to specified fiber.Router
func SetupEventHandlers(ctrl got5.EventHandler, auth got5.Auth, r gin.IRoutes) {
r.POST("/event", CheckEventHandlerAuth(auth), OnEventHandler(ctrl))
func SetupEventHandlers(ctrl got5.EventHandler, auth got5.Auth, authHeaderkey string, r gin.IRoutes) {
r.POST("/event", CheckEventHandlerAuth(auth, authHeaderkey), OnEventHandler(ctrl))
}

0 comments on commit 4c81f83

Please sign in to comment.