@@ -2,6 +2,7 @@ package auth
2
2
3
3
import (
4
4
"OPP/auth/api"
5
+ "OPP/auth/dao"
5
6
opp_jwt "OPP/auth/jwt"
6
7
"context"
7
8
"errors"
@@ -38,10 +39,24 @@ func AuthenticationWrapperFunc(ctx context.Context, input *openapi3filter.Authen
38
39
// AuthenticationFunc can be used for endpoints that aren't marked as requiring authentication
39
40
// but still need to check auth tokens when provided.
40
41
// Returns (username, role, error) where error is nil if authentication succeeded
41
- func AuthenticationFunc (authHeader string ) (string , api. UserRequestRole , error ) {
42
+ func AuthenticationFunc (authHeader string ) (string , string , error ) {
42
43
// Debug mode: override username and role
43
44
if DEBUG_MODE == "true" {
44
- return "admin_debug" , api .UserRequestRoleAdmin , nil
45
+ // make sure to create a debug user if it doesn't exist
46
+ role := api .UserRequestRoleAdmin
47
+ debug_user := api.UserRequest {
48
+ Username : "admin_debug" ,
49
+ Password : "admin_debug" ,
50
+ Role : & role ,
51
+ Email : "admin.debug@debug.com" ,
52
+ Name : "Admin" ,
53
+ Surname : "Debug" ,
54
+ }
55
+ _ , err := dao .NewUserDao ().AddUser (context .Background (), debug_user )
56
+ if err != nil && ! errors .Is (err , dao .ErrUserAlreadyExists ) {
57
+ return "" , "" , errors .New ("failed to create debug user: " + err .Error ())
58
+ }
59
+ return "admin_debug" , "admin" , nil
45
60
}
46
61
47
62
if authHeader == "" {
@@ -83,6 +98,5 @@ func AuthenticationFunc(authHeader string) (string, api.UserRequestRole, error)
83
98
return "" , "" , errors .New ("missing role in token claims" )
84
99
}
85
100
86
- role := api .UserRequestRole (roleStr )
87
- return username , role , nil
101
+ return username , roleStr , nil
88
102
}
0 commit comments