Skip to content

Commit 4ebdffa

Browse files
committed
fix: adding coderabbit suggestions
1 parent f071914 commit 4ebdffa

6 files changed

Lines changed: 11 additions & 6 deletions

File tree

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ TINYAUTH_LOG_STREAMS_APP_LEVEL="info"
2626
TINYAUTH_LOG_STREAMS_HTTP_ENABLED="true"
2727
TINYAUTH_LOG_STREAMS_HTTP_LEVEL="info"
2828
TINYAUTH_LOG_STREAMS_AUDIT_ENABLED="false"
29+
TINYAUTH_LOG_STREAMS_AUDIT_LEVEL="info"
2930

3031
# Server Configuration
3132

config.example.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ log:
2020
json: false
2121
streams:
2222
app:
23+
enabled: true
2324
level: "warn"
2425
http:
26+
enabled: true
2527
level: "debug"
2628
audit:
2729
enabled: false
30+
level: "info"
2831

2932
# Server Configuration
3033
server:

internal/controller/oauth_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func (controller *OAuthController) oauthCallbackHandler(c *gin.Context) {
155155

156156
if !controller.auth.IsEmailWhitelisted(user.Email) {
157157
tlog.App.Warn().Str("email", user.Email).Msg("Email not whitelisted")
158+
tlog.AuditLoginFailure(c, user.Email, req.Provider, "email not whitelisted")
158159

159160
queries, err := query.Values(config.UnauthorizedQuery{
160161
Username: user.Email,

internal/controller/user_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (controller *UserController) loginHandler(c *gin.Context) {
6767

6868
if isLocked {
6969
tlog.App.Warn().Str("username", req.Username).Msg("Account is locked due to too many failed login attempts")
70-
tlog.AuditLoginFailure(c, req.Username, "username")
70+
tlog.AuditLoginFailure(c, req.Username, "username", "account locked")
7171
c.Writer.Header().Add("x-tinyauth-lock-locked", "true")
7272
c.Writer.Header().Add("x-tinyauth-lock-reset", time.Now().Add(time.Duration(remaining)*time.Second).Format(time.RFC3339))
7373
c.JSON(429, gin.H{
@@ -82,7 +82,7 @@ func (controller *UserController) loginHandler(c *gin.Context) {
8282
if userSearch.Type == "unknown" {
8383
tlog.App.Warn().Str("username", req.Username).Msg("User not found")
8484
controller.auth.RecordLoginAttempt(req.Username, false)
85-
tlog.AuditLoginFailure(c, req.Username, "username")
85+
tlog.AuditLoginFailure(c, req.Username, "username", "user not found")
8686
c.JSON(401, gin.H{
8787
"status": 401,
8888
"message": "Unauthorized",
@@ -93,7 +93,7 @@ func (controller *UserController) loginHandler(c *gin.Context) {
9393
if !controller.auth.VerifyUser(userSearch, req.Password) {
9494
tlog.App.Warn().Str("username", req.Username).Msg("Invalid password")
9595
controller.auth.RecordLoginAttempt(req.Username, false)
96-
tlog.AuditLoginFailure(c, req.Username, "username")
96+
tlog.AuditLoginFailure(c, req.Username, "username", "invalid password")
9797
c.JSON(401, gin.H{
9898
"status": 401,
9999
"message": "Unauthorized",
@@ -235,7 +235,7 @@ func (controller *UserController) totpHandler(c *gin.Context) {
235235
if !ok {
236236
tlog.App.Warn().Str("username", context.Username).Msg("Invalid TOTP code")
237237
controller.auth.RecordLoginAttempt(context.Username, false)
238-
tlog.AuditLoginFailure(c, context.Username, "totp")
238+
tlog.AuditLoginFailure(c, context.Username, "totp", "invalid totp code")
239239
c.JSON(401, gin.H{
240240
"status": 401,
241241
"message": "Unauthorized",

internal/service/oauth_broker_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (broker *OAuthBrokerService) Init() error {
4949
for name, service := range broker.services {
5050
err := service.Init()
5151
if err != nil {
52-
tlog.App.Error().Err(err).Msgf("Failed to initialize OAuth service: %T", name)
52+
tlog.App.Error().Err(err).Msgf("Failed to initialize OAuth service: %s", name)
5353
return err
5454
}
5555
tlog.App.Info().Str("service", name).Msg("Initialized OAuth service")

internal/utils/tlog/log_audit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func AuditLoginSuccess(c *gin.Context, username, provider string) {
1212
Send()
1313
}
1414

15-
func AuditLoginFailure(c *gin.Context, username, provider string) {
15+
func AuditLoginFailure(c *gin.Context, username, provider string, reason string) {
1616
Audit.Warn().
1717
Str("event", "login").
1818
Str("result", "failure").

0 commit comments

Comments
 (0)