Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: add logs to oauth2 (#4486)
boojackfd0f30ecf45d
diff --git a/backend/plugin/idp/oauth2/oauth2.go b/backend/plugin/idp/oauth2/oauth2.goindex 01c32cafd7..ba468edcd8 100644--- a/backend/plugin/idp/oauth2/oauth2.go+++ b/backend/plugin/idp/oauth2/oauth2.go@@ -9,8 +9,10 @@ import ("net/http""github.com/pkg/errors"+ "go.uber.org/zap""golang.org/x/oauth2"+ "github.com/bytebase/bytebase/backend/common/log"storepb "github.com/bytebase/bytebase/proto/generated-go/store")@@ -54,11 +56,13 @@ func (p *IdentityProvider) ExchangeToken(ctx context.Context, redirectURL, codetoken, err := conf.Exchange(ctx, code)if err != nil {- return "", errors.Wrap(err, "failed to exchange OAuth token")+ log.Error("Failed to exchange access token", zap.String("code", code), zap.Error(err))+ return "", errors.Wrap(err, "failed to exchange access token")}accessToken, ok := token.Extra("access_token").(string)if !ok {+ log.Error(`Missing "access_token" from authorization response`, zap.String("code", code), zap.Any("token", token))return "", errors.New(`missing "access_token" from authorization response`)}@@ -76,17 +80,20 @@ func (p *IdentityProvider) UserInfo(token string) (*storepb.IdentityProviderUserreq.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))resp, err := client.Do(req)if err != nil {- return nil, errors.Wrap(err, "failed to get user info")+ log.Error("Failed to get user information", zap.String("token", token), zap.Error(err))+ return nil, errors.Wrap(err, "failed to get user information")}body, err := io.ReadAll(resp.Body)if err != nil {+ log.Error("Failed to read response body", zap.String("token", token), zap.Error(err))return nil, errors.Wrap(err, "failed to read response body")}var claims map[string]anyerr = json.Unmarshal(body, &claims)if err != nil {- return nil, errors.Wrap(err, "failed to unmarshal raw response body")+ log.Error("Failed to unmarshal response body", zap.String("token", token), zap.String("body", string(body)), zap.Error(err))+ return nil, errors.Wrap(err, "failed to unmarshal response body")}userInfo := &storepb.IdentityProviderUserInfo{}@@ -94,6 +101,7 @@ func (p *IdentityProvider) UserInfo(token string) (*storepb.IdentityProviderUseruserInfo.Identifier = v}if userInfo.Identifier == "" {+ log.Error("Missing identifier in response body", zap.String("token", token), zap.Any("claims", claims), zap.Error(err))return nil, errors.Errorf("the field %q is not found in claims or has empty value", p.config.FieldMapping.Identifier)}