Skip to content

Commit

Permalink
Merge pull request #5 from DrOctavius/main
Browse files Browse the repository at this point in the history
broker service auth fixes
  • Loading branch information
DrOctavius authored Aug 4, 2022
2 parents 3a7b3ff + 7d96396 commit e9a1f31
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions core/services/broker/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,40 @@ import (
)

func (b *Broker) CheckIsAuthenticated() gin.HandlerFunc {
return authentication.
CheckIsAuthenticated().
//ByHeaderKeys([]string{"Auth-Token"}).
//ByGetParams([]string{"AuthToken"}).
OnTokenInValid(func(a *authentication.Auth) {
warn := func() *zerolog.Event {
return b.LWarnF("CheckIsAuthenticated")
}
warn().Msg("authentication token is not available")
return func(context *gin.Context) {
authentication.New().SetGinContext(context).
//ByHeaderKeys([]string{"Auth-Token"}).
//ByGetParams([]string{"AuthToken"}).
OnTokenInValid(func(a *authentication.Auth) {
warn := func() *zerolog.Event {
return b.LWarnF("CheckIsAuthenticated")
}
warn().Msg("authentication token is not available")

a.Abort(
1000,
403,
"Authentication token is not available!",
)
}).
OnTokenValid(func(a *authentication.Auth) {
// Check here
info := func() *zerolog.Event {
return b.LInfoF("CheckIsAuthenticated")
}

token := a.GetToken()
if token != b.config.AuthToken {
info().Str("received_token", token).Msg(color.Style{color.LightRed, color.Bold}.Render("authentication failed"))
a.Abort(
2000,
1000,
403,
"Authentication Token is Invalid!",
"Authentication token is not available!",
)
}
info().Msg(color.Style{color.LightGreen, color.Bold}.Render("authentication success"))
}).
OnTokenValid(func(a *authentication.Auth) {
// Check here
info := func() *zerolog.Event {
return b.LInfoF("CheckIsAuthenticated")
}

token := a.GetToken()
if token != b.config.AuthToken {
info().Str("received_token", token).Msg(color.Style{color.LightRed, color.Bold}.Render("authentication failed"))
a.Abort(
2000,
403,
"Authentication Token is Invalid!",
)
}
info().Msg(color.Style{color.LightGreen, color.Bold}.Render("authentication success"))

}).
GetHandlerFunc()
}).
Check()
}
}

0 comments on commit e9a1f31

Please sign in to comment.