Skip to content

Commit 903abba

Browse files
authored
fix: Go and JS clients should not require v1+v2 auth (deephaven#5946)
The Go client required sending v2 auth, but receiving v1 responses - this change makes it consistently use v1 auth. The JS client incorrectly closed the stream only after it had received headers - now it can close right away, and just wait for headers to arrive normally. Prerequisite to deephaven#5922
1 parent 663fae6 commit 903abba

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

go/pkg/client/tokens.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"fmt"
88
"github.com/apache/arrow/go/v8/arrow/flight"
99
configpb2 "github.com/deephaven/deephaven-core/go/internal/proto/config"
10+
sessionpb2 "github.com/deephaven/deephaven-core/go/internal/proto/session"
1011
"google.golang.org/grpc/metadata"
12+
"google.golang.org/protobuf/proto"
1113
"log"
1214
"strconv"
1315
"sync"
@@ -36,8 +38,19 @@ func withAuthToken(ctx context.Context, token []byte) context.Context {
3638
}
3739

3840
// requestToken requests a new token from flight.
39-
func requestToken(handshakeClient flight.FlightService_HandshakeClient, handshakeReq *flight.HandshakeRequest) ([]byte, error) {
40-
err := handshakeClient.Send(handshakeReq)
41+
func requestToken(handshakeClient flight.FlightService_HandshakeClient, authType string, authToken []byte) ([]byte, error) {
42+
43+
war := sessionpb2.WrappedAuthenticationRequest{
44+
Type: authType,
45+
Payload: authToken,
46+
}
47+
payload, err := proto.Marshal(&war)
48+
if err != nil {
49+
return nil, err
50+
}
51+
handshakeReq := flight.HandshakeRequest{Payload: []byte(payload)}
52+
53+
err = handshakeClient.Send(&handshakeReq)
4154

4255
if err != nil {
4356
return nil, err
@@ -122,15 +135,13 @@ func (tr *tokenManager) Close() error {
122135
// "user:password"; when auth_type is DefaultAuth, it will be ignored; when auth_type is a custom-built
123136
// authenticator, it must conform to the specific requirement of the authenticator.
124137
func newTokenManager(ctx context.Context, fs *flightStub, cfg configpb2.ConfigServiceClient, authType string, authToken string) (*tokenManager, error) {
125-
authString := makeAuthString(authType, authToken)
126-
127-
handshakeClient, err := fs.handshake(withAuth(ctx, authString))
138+
handshakeClient, err := fs.handshake(ctx)
128139

129140
if err != nil {
130141
return nil, err
131142
}
132143

133-
tkn, err := requestToken(handshakeClient, &flight.HandshakeRequest{Payload: []byte(authString)})
144+
tkn, err := requestToken(handshakeClient, authType, []byte(authToken))
134145

135146
if err != nil {
136147
return nil, err
@@ -174,10 +185,10 @@ func newTokenManager(ctx context.Context, fs *flightStub, cfg configpb2.ConfigSe
174185
var tkn []byte
175186

176187
if err == nil {
177-
tkn, err = requestToken(handshakeClient, &flight.HandshakeRequest{Payload: oldToken})
188+
tkn, err = requestToken(handshakeClient, "Bearer", oldToken)
178189
} else {
179190
log.Println("Old token has an error during token update. Attempting to acquire a fresh token. err=", err)
180-
tkn, err = requestToken(handshakeClient, &flight.HandshakeRequest{Payload: []byte(authString)})
191+
tkn, err = requestToken(handshakeClient, authType, []byte(authToken))
181192
}
182193

183194
if err != nil {

web/client-api/src/main/java/io/deephaven/web/client/api/WorkerConnection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ private Promise<Void> authUpdate() {
496496
info.fireEvent(EVENT_REFRESH_TOKEN_UPDATED, init);
497497
}
498498
}
499-
handshake.end();
500499
});
501500
handshake.onStatus(status -> {
502501
if (status.isOk()) {
@@ -526,6 +525,7 @@ private Promise<Void> authUpdate() {
526525
});
527526

528527
handshake.send(new HandshakeRequest());
528+
handshake.end();
529529
});
530530
}
531531

0 commit comments

Comments
 (0)