rambleraptor commented on code in PR #579:
URL: https://github.com/apache/iceberg-go/pull/579#discussion_r2604152900


##########
catalog/rest/rest.go:
##########
@@ -574,23 +490,35 @@ func (r *Catalog) createSession(ctx context.Context, opts 
*options) (*http.Clien
        }
        cl := &http.Client{Transport: session}
 
-       token := opts.oauthToken
-       if token == "" && opts.credential != "" {
-               var err error
-               if token, err = r.fetchAccessToken(cl, opts.credential, opts); 
err != nil {
-                       return nil, fmt.Errorf("auth error: %w", err)
-               }
-       }
+       if opts.credential != "" {
+               if _, ok := opts.authManager.(*Oauth2AuthManager); !ok {
+                       authURI := opts.authUri
+                       if authURI == nil {
+                               authURI = r.baseURI.JoinPath("oauth/tokens")
+                       }
 
-       if token != "" {
-               session.defaultHeaders.Set(authorizationHeader, bearerPrefix+" 
"+token)
+                       opts.authManager = &Oauth2AuthManager{
+                               Credential: opts.credential,
+                               AuthURI:    authURI,
+                               Scope:      opts.scope,
+                               Client:     cl,
+                       }
+               }

Review Comment:
   The Java + Python implementations don't have an `AuthURI` method and I'm 
inclined to agree with it. All the AuthManager should do is provide a header. 
How that header is determined (maybe it involves a URI being called, maybe it's 
just reading the token from a file!) is completely up to the AuthManager.
   
   The goal of this particular spot was to handle the case where no AuthManager 
is set, since we should do the current, default behavior. I've added some 
comments to help emphasize this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to