@@ -16,10 +16,8 @@ import (
16
16
"net/http"
17
17
"os"
18
18
"regexp"
19
- "time"
20
19
21
20
"github.com/fatih/color"
22
- "github.com/golang-jwt/jwt/v5"
23
21
"github.com/hypermodeinc/modus/lib/manifest"
24
22
"github.com/hypermodeinc/modus/runtime/logger"
25
23
"github.com/hypermodeinc/modus/runtime/utils"
@@ -94,57 +92,24 @@ func ApplySecretsToHttpRequest(ctx context.Context, connection *manifest.HTTPCon
94
92
95
93
func ApplyAuthToLocalHypermodeModelRequest (ctx context.Context , connection manifest.ConnectionInfo , req * http.Request ) error {
96
94
97
- jwt := os .Getenv ("HYP_JWT " )
98
- orgId := os .Getenv ("HYP_ORG_ID " )
95
+ apiKey := os .Getenv ("HYP_API_KEY " )
96
+ workspaceId := os .Getenv ("HYP_WORKSPACE_ID " )
99
97
100
98
warningColor := color .New (color .FgHiYellow , color .Bold )
101
99
102
- if jwt == "" || orgId == "" {
100
+ if apiKey == "" || workspaceId == "" {
103
101
fmt .Fprintln (os .Stderr )
104
102
warningColor .Fprintln (os .Stderr , "Warning: Local authentication not found. Please login using `hyp login`" )
105
103
fmt .Fprintln (os .Stderr )
106
104
return errLocalAuthFailed
107
105
}
108
106
109
- isExpired , err := checkJWTExpiration (jwt )
110
- if err != nil {
111
- return err
112
- }
113
- if isExpired {
114
- fmt .Fprintln (os .Stderr )
115
- warningColor .Fprintln (os .Stderr , "Warning: Local authentication expired. Please login using `hyp login`" )
116
- fmt .Fprintln (os .Stderr )
117
- return errLocalAuthFailed
118
- }
119
-
120
- req .Header .Set ("Authorization" , "Bearer " + jwt )
121
- req .Header .Set ("HYP-ORG-ID" , orgId )
107
+ req .Header .Set ("Authorization" , "Bearer " + apiKey )
108
+ req .Header .Set ("HYP-WORKSPACE-ID" , workspaceId )
122
109
123
110
return nil
124
111
}
125
112
126
- // checkJWTExpiration checks if the JWT has expired based on the 'exp' claim.
127
- func checkJWTExpiration (tokenString string ) (bool , error ) {
128
- p := jwt.Parser {}
129
- token , _ , err := p .ParseUnverified (tokenString , jwt.MapClaims {})
130
- if err != nil {
131
- return false , fmt .Errorf ("failed to parse: %w" , err )
132
- }
133
-
134
- claims , ok := token .Claims .(jwt.MapClaims )
135
- if ! ok {
136
- return false , fmt .Errorf ("failed to extract claims from JWT" )
137
- }
138
-
139
- exp , ok := claims ["exp" ].(float64 )
140
- if ! ok {
141
- return false , fmt .Errorf ("exp claim is missing or not a number" )
142
- }
143
-
144
- expirationTime := time .Unix (int64 (exp ), 0 )
145
- return time .Now ().After (expirationTime ), nil
146
- }
147
-
148
113
// ApplySecretsToString evaluates the given string and replaces any placeholders
149
114
// present in the string with their secret values for the given connection.
150
115
func ApplySecretsToString (ctx context.Context , connection manifest.ConnectionInfo , str string ) (string , error ) {
0 commit comments