File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ func main() {
9898 Bytes : publicKeyBytes ,
9999 })
100100
101- encryptedKey , err := security.GetApiSecurityService [api_context.DefaultContext ](appEnv .ApiSecretAuthorization ).Encrypt (string (publicKeyPEM ))
101+ encryptedKey , err := security.GetApiSecurityService [* api_context.DefaultContext ](appEnv .ApiSecretAuthorization ).Encrypt (string (publicKeyPEM ))
102102
103103 if err != nil {
104104 log .Fatalf ("Failed to sec public key: %s" , err )
@@ -120,13 +120,14 @@ func main() {
120120 return
121121 }
122122
123+ expirationToken := time .Hour * (time .Duration (* expirationHours ))
123124 apiJWTInfo := security.ApiJWTInfo {
124125 Client : * clientInfo ,
125- Expiration : time . Duration ( * expirationHours ) ,
126+ Expiration : expirationToken ,
126127 Key : * id ,
127128 }
128129
129- apiSecretJWT , err := security.GetApiSecurityService [api_context.DefaultContext ](appEnv .ApiSecretAuthorization ).GenerateApiSecretJWT (apiJWTInfo )
130+ apiSecretJWT , err := security.GetApiSecurityService [* api_context.DefaultContext ](appEnv .ApiSecretAuthorization ).GenerateApiSecretJWT (apiJWTInfo )
130131
131132 if err != nil {
132133 return
Original file line number Diff line number Diff line change @@ -16,9 +16,9 @@ import (
1616
1717func main () {
1818 appEnv := env .AppEnv ()
19- db .InitMongoDB ()
2019 service := user_service .GetService ()
2120 userAuthenticationUserHandler := user_handler .GetAuthenticationUserHandler (& service )
21+
2222 api := server .New [* request.ApiContext ](
2323 request .ContextBuilder ,
2424 userAuthenticationUserHandler .Handler ,
@@ -28,6 +28,9 @@ func main() {
2828 securityService := security.GetApiSecurityService [* request.ApiContext ](appEnv .ApiSecretAuthorization )
2929 auth .Handler (appEnv .ApiSecretKey , secretService .GetKey , & securityService , api )
3030 handlers .Init (api )
31+
32+ db .InitMongoDB ()
33+
3134 peer .GetService ().Load ()
3235 service .Init ()
3336 api .StartServer ()
Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ github.com/softwareplace/http-utils v0.0.0-20250117224835-13ee112340a6 h1:uxMnbp
2626github.com/softwareplace/http-utils v0.0.0-20250117224835-13ee112340a6 /go.mod h1:5o/vgMsC67X2DChcdR76qm8yyjkIKmSFHudNeaK060U =
2727github.com/softwareplace/http-utils v0.0.0-20250117231145-c67f294855cd h1:NTHsh5xr4DlIGwaNrEuq7vREYryGPZol7qFYsQgPl8s =
2828github.com/softwareplace/http-utils v0.0.0-20250117231145-c67f294855cd /go.mod h1:5o/vgMsC67X2DChcdR76qm8yyjkIKmSFHudNeaK060U =
29+ github.com/softwareplace/http-utils v0.0.0-20250118003817-f2b4ec9b8676 h1:pTZv6az0E/CQBbVXUROyWQjdaFyamMMkz2YYvRf9CmI =
30+ github.com/softwareplace/http-utils v0.0.0-20250118003817-f2b4ec9b8676 /go.mod h1:5o/vgMsC67X2DChcdR76qm8yyjkIKmSFHudNeaK060U =
2931github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c =
3032github.com/xdg-go/pbkdf2 v1.0.0 /go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI =
3133github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY =
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ func GetService() ApiSecretService {
2121}
2222
2323func (s * serviceImpl ) GetKey (ctx * api_context.ApiRequestContext [* request.ApiContext ]) (string , error ) {
24- apiSecret , err := s .repository .GetById (ctx .ApiKey )
24+ apiSecret , err := s .repository .GetById (ctx .RequestData . ApiKeyId )
2525 if err != nil {
2626 return "" , err
2727 }
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import (
1111 "github.com/softwareplace/wireguard-api/pkg/utils/sec"
1212 "github.com/softwareplace/wireguard-api/pkg/utils/validator"
1313 "log"
14- "net/http"
1514)
1615
1716type Service interface {
@@ -26,14 +25,17 @@ type serviceImpl struct {
2625}
2726
2827func (s * serviceImpl ) LoadUserRoles (ctx api_context.ApiRequestContext [* request.ApiContext ]) []string {
29- user , err := s .repository .FindUserBySalt (ctx .RequestData .Salt ())
30- if err != nil {
31- log .Printf ("[%s]:: error finding user: %v" , ctx .GetSessionId (), err )
32- ctx .Error ("Error finding user in the database" , http .StatusInternalServerError )
33- return nil
28+ if s .securityService .ExtractJWTClaims (ctx ) {
29+ user , err := s .repository .FindUserBySalt (ctx .RequestData .AccessId )
30+ if err != nil {
31+ log .Printf ("[%s]:: error finding user: %v" , ctx .GetSessionId (), err )
32+ return nil
33+ }
34+ ctx .RequestData .User = user
35+ return user .Roles
3436 }
35- ctx . RequestData . User = user
36- return user . Roles
37+
38+ return nil
3739}
3840
3941func GetService () Service {
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ func (h *handlerImpl) checkUserCredentials(ctx *api_context.ApiRequestContext[*r
4545 return
4646 }
4747
48+ ctx .RequestData .User = userResponse
4849 // Generate JWT and respond
4950 tokenData , err := h .ApiSecurityService ().GenerateJWT (ctx .RequestData , time .Minute * 10 )
5051 if err != nil {
You can’t perform that action at this time.
0 commit comments