@rivascva/dt-idl 1.1.103 → 1.1.104

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.
Files changed (2) hide show
  1. package/go/auth/jwt.go +28 -0
  2. package/package.json +1 -1
package/go/auth/jwt.go CHANGED
@@ -40,6 +40,16 @@ func NewServiceAccessToken(accessTokenSecret string, issuer string, service stri
40
40
  return newAccessToken(accessTokenSecret, "service", issuer, service, duration)
41
41
  }
42
42
 
43
+ // NewUserRefreshToken creates a new JWT refresh token for the given user id.
44
+ func NewUserRefreshToken(refreshTokenSecret string, issuer string, userId string, duration time.Duration) (string, error) {
45
+ return newRefreshToken(refreshTokenSecret, issuer, userId, duration)
46
+ }
47
+
48
+ // NewServiceRefreshToken creates a new JWT refresh token for the given service.
49
+ func NewServiceRefreshToken(refreshTokenSecret string, issuer string, service string, duration time.Duration) (string, error) {
50
+ return newRefreshToken(refreshTokenSecret, issuer, service, duration)
51
+ }
52
+
43
53
  // newAccessToken creates a new JWT access token.
44
54
  func newAccessToken(accessTokenSecret string, ttype string, issuer string, subject string, duration time.Duration) (string, error) {
45
55
  t := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
@@ -57,3 +67,21 @@ func newAccessToken(accessTokenSecret string, ttype string, issuer string, subje
57
67
 
58
68
  return s, nil
59
69
  }
70
+
71
+ // newRefreshToken creates a new JWT refresh token.
72
+ func newRefreshToken(refreshTokenSecret string, issuer string, subject string, duration time.Duration) (string, error) {
73
+ t := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
74
+ "type": "refresh",
75
+ "iss": issuer,
76
+ "sub": subject,
77
+ "iat": time.Now().UnixMilli(),
78
+ "exp": time.Now().Add(duration).UnixMilli(),
79
+ })
80
+
81
+ s, err := t.SignedString([]byte(refreshTokenSecret))
82
+ if err != nil {
83
+ return "", fmt.Errorf("unable to sign the refresh token: %w", err)
84
+ }
85
+
86
+ return s, nil
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivascva/dt-idl",
3
- "version": "1.1.103",
3
+ "version": "1.1.104",
4
4
  "description": "Dream Trade - Interface Definition Language",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",