@rivascva/dt-idl 1.1.84 → 1.1.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/go/{jwt → auth}/jwt.go
RENAMED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
package auth
|
|
2
|
+
|
|
3
|
+
import "time"
|
|
4
|
+
|
|
5
|
+
// DefaultServiceTokenDuration is the default duration for service tokens.
|
|
6
|
+
const DefaultServiceTokenDuration = 30 * time.Minute
|
|
7
|
+
|
|
8
|
+
// approvedServices is a list of services that are allowed to access sensitive data.
|
|
9
|
+
var approvedServices = []string{"dt-trade-service", "dt-portfolio-service", "dt-asset-service", "dt-user-service"}
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
package
|
|
1
|
+
package auth
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
"context"
|
|
5
5
|
"fmt"
|
|
6
6
|
"slices"
|
|
7
|
-
)
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
"github.com/RivasCVA/dt-idl/go/utils"
|
|
9
|
+
)
|
|
11
10
|
|
|
12
11
|
// CanActorAccessUserId checks if the actor is allowed to access data for the user id.
|
|
13
12
|
func CanActorAccessUserId(ctx context.Context, userId string) (bool, error) {
|
|
14
13
|
// get the actor id from the context
|
|
15
|
-
actorId, err := GetActorIdFromContext(ctx)
|
|
14
|
+
actorId, err := utils.GetActorIdFromContext(ctx)
|
|
16
15
|
if err != nil {
|
|
17
16
|
return false, fmt.Errorf("failed to get the actor id from the context: %w", err)
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
// get the token type from the context
|
|
21
|
-
tokenType, err := GetTokenTypeFromContext(ctx)
|
|
20
|
+
tokenType, err := utils.GetTokenTypeFromContext(ctx)
|
|
22
21
|
if err != nil {
|
|
23
22
|
return false, fmt.Errorf("failed to get the token type from the context: %w", err)
|
|
24
23
|
}
|
|
@@ -6,7 +6,7 @@ import (
|
|
|
6
6
|
"slices"
|
|
7
7
|
"strings"
|
|
8
8
|
|
|
9
|
-
"github.com/RivasCVA/dt-idl/go/
|
|
9
|
+
"github.com/RivasCVA/dt-idl/go/auth"
|
|
10
10
|
"github.com/RivasCVA/dt-idl/go/log"
|
|
11
11
|
"github.com/RivasCVA/dt-idl/go/models"
|
|
12
12
|
"github.com/RivasCVA/dt-idl/go/write"
|
|
@@ -35,7 +35,7 @@ func GetAuthMiddleware(secret string) func(http.Handler) http.Handler {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// validate the token
|
|
38
|
-
token, err :=
|
|
38
|
+
token, err := auth.ValidateToken(arr[1], secret)
|
|
39
39
|
if err != nil {
|
|
40
40
|
write.ResponseWithError(r.Context(), w, http.StatusUnauthorized, "invalid token")
|
|
41
41
|
return
|
package/package.json
CHANGED