Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor(mcp): store the refresh token's grant state as a config proto
Vincent Huangbb0532b2b7c6
diff --git a/backend/api/oauth2/grant_test.go b/backend/api/oauth2/grant_test.goindex 62501c91b5..4b1f7a19bd 100644--- a/backend/api/oauth2/grant_test.go+++ b/backend/api/oauth2/grant_test.go@@ -193,8 +193,8 @@ func TestResourceScopeGrantLifecycle(t *testing.T) {stored, err := st.GetOAuth2RefreshToken(ctx, testClientID, auth.HashToken(first.RefreshToken))require.NoError(t, err)require.NotNil(t, stored)- require.Equal(t, testResource, stored.Resource)- require.Equal(t, "mcp:read-write", stored.Scope)+ require.Equal(t, testResource, stored.Config.GetResource())+ require.Equal(t, "mcp:read-write", stored.Config.GetScope())// A refresh that names a wider scope is refused, and refusal happens// before consumption so the client can retry correctly.@@ -228,8 +228,8 @@ func TestResourceScopeGrantLifecycle(t *testing.T) {rotated, err := st.GetOAuth2RefreshToken(ctx, testClientID, auth.HashToken(second.RefreshToken))require.NoError(t, err)require.NotNil(t, rotated)- require.Equal(t, testResource, rotated.Resource)- require.Equal(t, "mcp:read-write", rotated.Scope)+ require.Equal(t, testResource, rotated.Config.GetResource())+ require.Equal(t, "mcp:read-write", rotated.Config.GetScope())})t.Run("a bare-origin grant refreshes as the canonical resource, named either way", func(t *testing.T) {@@ -250,7 +250,7 @@ func TestResourceScopeGrantLifecycle(t *testing.T) {stored, err := st.GetOAuth2RefreshToken(ctx, testClientID, auth.HashToken(first.RefreshToken))require.NoError(t, err)require.NotNil(t, stored)- require.Equal(t, testResource, stored.Resource)+ require.Equal(t, testResource, stored.Config.GetResource())second := tokenOK(t, configured, url.Values{"grant_type": {"refresh_token"},@@ -261,7 +261,7 @@ func TestResourceScopeGrantLifecycle(t *testing.T) {rotated, err := st.GetOAuth2RefreshToken(ctx, testClientID, auth.HashToken(second.RefreshToken))require.NoError(t, err)require.NotNil(t, rotated)- require.Equal(t, testResource, rotated.Resource,+ require.Equal(t, testResource, rotated.Config.GetResource(),"the canonical form must survive rotation, not drift back to what the client sent")})@@ -289,8 +289,8 @@ func TestResourceScopeGrantLifecycle(t *testing.T) {stored, err := st.GetOAuth2RefreshToken(ctx, testClientID, auth.HashToken(first.RefreshToken))require.NoError(t, err)require.NotNil(t, stored)- require.Empty(t, stored.Resource, "the requested resource must be ignored, never bound to a grant that never consented to one")- require.Empty(t, stored.Scope)+ require.Empty(t, stored.Config.GetResource(), "the requested resource must be ignored, never bound to a grant that never consented to one")+ require.Empty(t, stored.Config.GetScope())// And the same on refresh, so a legacy session keeps working indefinitely// until PR 3 retires it deliberately.@@ -303,7 +303,7 @@ func TestResourceScopeGrantLifecycle(t *testing.T) {rotated, err := st.GetOAuth2RefreshToken(ctx, testClientID, auth.HashToken(second.RefreshToken))require.NoError(t, err)require.NotNil(t, rotated)- require.Empty(t, rotated.Resource)+ require.Empty(t, rotated.Config.GetResource())})t.Run("consent rejects two scope tiers in one parameter", func(t *testing.T) {diff --git a/backend/api/oauth2/token.go b/backend/api/oauth2/token.goindex 478fab3959..c9e809442e 100644--- a/backend/api/oauth2/token.go+++ b/backend/api/oauth2/token.go@@ -16,6 +16,7 @@ import ("github.com/bytebase/bytebase/backend/api/auth""github.com/bytebase/bytebase/backend/common/log"+ storepb "github.com/bytebase/bytebase/backend/generated-go/store""github.com/bytebase/bytebase/backend/store")@@ -268,10 +269,10 @@ func (s *Service) handleRefreshTokenGrant(c *echo.Context, client *store.OAuth2C// are carried forward verbatim, and a request naming different ones is// rejected rather than honored. Checked before the token is consumed so a// rejected refresh leaves the client able to retry correctly.- if failure := checkConsentedResource(formValues, refreshToken.Resource); failure != nil {+ if failure := checkConsentedResource(formValues, refreshToken.Config.GetResource()); failure != nil {return tokenFailure(c, failure)}- if failure := checkConsentedScope(formValues, refreshToken.Scope); failure != nil {+ if failure := checkConsentedScope(formValues, refreshToken.Config.GetScope()); failure != nil {return tokenFailure(c, failure)}@@ -308,8 +309,8 @@ func (s *Service) handleRefreshTokenGrant(c *echo.Context, client *store.OAuth2Creturn s.issueTokens(c, client, issuedGrant{userEmail: user.Email,workspaceID: workspaceID,- resource: refreshToken.Resource,- scope: refreshToken.Scope,+ resource: refreshToken.Config.GetResource(),+ scope: refreshToken.Config.GetScope(),})}@@ -416,8 +417,10 @@ func (s *Service) issueTokens(c *echo.Context, client *store.OAuth2ClientMessageClientID: client.ClientID,UserEmail: grant.userEmail,Workspace: grant.workspaceID,- Resource: grant.resource,- Scope: grant.scope,+ Config: &storepb.OAuth2RefreshTokenConfig{+ Resource: grant.resource,+ Scope: grant.scope,+ },ExpiresAt: now.Add(refreshTokenExpiry),}); err != nil {return oauth2Error(c, http.StatusInternalServerError, "server_error", "failed to store refresh token")diff --git a/backend/generated-go/store/oauth2.pb.go b/backend/generated-go/store/oauth2.pb.goindex 2837ebbb40..b01b6155b1 100644--- a/backend/generated-go/store/oauth2.pb.go+++ b/backend/generated-go/store/oauth2.pb.go@@ -89,6 +89,67 @@ func (x *OAuth2ClientConfig) GetTokenEndpointAuthMethod() string {return ""}+// OAuth2RefreshTokenConfig is the consented grant state carried from the+// authorization code onto every refresh token issued from it, and re-issued+// unchanged by each refresh. Kept as a message rather than flat columns so the+// grant can gain fields without a schema migration.+type OAuth2RefreshTokenConfig struct {+ state protoimpl.MessageState `protogen:"open.v1"`+ // The canonical resource URI (RFC 8707) this grant is bound to, validated at+ // consent time against the configured external URL. Empty for clients that+ // omit the resource parameter.+ Resource string `protobuf:"bytes,1,opt,name=resource,proto3" json:"resource,omitempty"`+ // The scope string consented to, stored verbatim. Empty means no scope was+ // requested.+ Scope string `protobuf:"bytes,2,opt,name=scope,proto3" json:"scope,omitempty"`+ unknownFields protoimpl.UnknownFields+ sizeCache protoimpl.SizeCache+}++func (x *OAuth2RefreshTokenConfig) Reset() {+ *x = OAuth2RefreshTokenConfig{}+ mi := &file_store_oauth2_proto_msgTypes[1]+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ ms.StoreMessageInfo(mi)+}++func (x *OAuth2RefreshTokenConfig) String() string {+ return protoimpl.X.MessageStringOf(x)+}++func (*OAuth2RefreshTokenConfig) ProtoMessage() {}++func (x *OAuth2RefreshTokenConfig) ProtoReflect() protoreflect.Message {+ mi := &file_store_oauth2_proto_msgTypes[1]+ if x != nil {+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ if ms.LoadMessageInfo() == nil {+ ms.StoreMessageInfo(mi)+ }+ return ms+ }+ return mi.MessageOf(x)+}++// Deprecated: Use OAuth2RefreshTokenConfig.ProtoReflect.Descriptor instead.+func (*OAuth2RefreshTokenConfig) Descriptor() ([]byte, []int) {+ return file_store_oauth2_proto_rawDescGZIP(), []int{1}+}++func (x *OAuth2RefreshTokenConfig) GetResource() string {+ if x != nil {+ return x.Resource+ }+ return ""+}++func (x *OAuth2RefreshTokenConfig) GetScope() string {+ if x != nil {+ return x.Scope+ }+ return ""+}+type OAuth2AuthorizationCodeConfig struct {state protoimpl.MessageState `protogen:"open.v1"`RedirectUri string `protobuf:"bytes,1,opt,name=redirect_uri,json=redirectUri,proto3" json:"redirect_uri,omitempty"`@@ -107,7 +168,7 @@ type OAuth2AuthorizationCodeConfig struct {func (x *OAuth2AuthorizationCodeConfig) Reset() {*x = OAuth2AuthorizationCodeConfig{}- mi := &file_store_oauth2_proto_msgTypes[1]+ mi := &file_store_oauth2_proto_msgTypes[2]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -119,7 +180,7 @@ func (x *OAuth2AuthorizationCodeConfig) String() string {func (*OAuth2AuthorizationCodeConfig) ProtoMessage() {}func (x *OAuth2AuthorizationCodeConfig) ProtoReflect() protoreflect.Message {- mi := &file_store_oauth2_proto_msgTypes[1]+ mi := &file_store_oauth2_proto_msgTypes[2]if x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -132,7 +193,7 @@ func (x *OAuth2AuthorizationCodeConfig) ProtoReflect() protoreflect.Message {// Deprecated: Use OAuth2AuthorizationCodeConfig.ProtoReflect.Descriptor instead.func (*OAuth2AuthorizationCodeConfig) Descriptor() ([]byte, []int) {- return file_store_oauth2_proto_rawDescGZIP(), []int{1}+ return file_store_oauth2_proto_rawDescGZIP(), []int{2}}func (x *OAuth2AuthorizationCodeConfig) GetRedirectUri() string {@@ -181,7 +242,10 @@ const file_store_oauth2_proto_rawDesc = "" +"\rredirect_uris\x18\x02 \x03(\tR\fredirectUris\x12\x1f\n" +"\vgrant_types\x18\x03 \x03(\tR\n" +"grantTypes\x12;\n" +- "\x1atoken_endpoint_auth_method\x18\x04 \x01(\tR\x17tokenEndpointAuthMethod\"\xcf\x01\n" ++ "\x1atoken_endpoint_auth_method\x18\x04 \x01(\tR\x17tokenEndpointAuthMethod\"L\n" ++ "\x18OAuth2RefreshTokenConfig\x12\x1a\n" ++ "\bresource\x18\x01 \x01(\tR\bresource\x12\x14\n" ++ "\x05scope\x18\x02 \x01(\tR\x05scope\"\xcf\x01\n" +"\x1dOAuth2AuthorizationCodeConfig\x12!\n" +"\fredirect_uri\x18\x01 \x01(\tR\vredirectUri\x12%\n" +"\x0ecode_challenge\x18\x02 \x01(\tR\rcodeChallenge\x122\n" +@@ -202,10 +266,11 @@ func file_store_oauth2_proto_rawDescGZIP() []byte {return file_store_oauth2_proto_rawDescData}-var file_store_oauth2_proto_msgTypes = make([]protoimpl.MessageInfo, 2)+var file_store_oauth2_proto_msgTypes = make([]protoimpl.MessageInfo, 3)var file_store_oauth2_proto_goTypes = []any{(*OAuth2ClientConfig)(nil), // 0: bytebase.store.OAuth2ClientConfig- (*OAuth2AuthorizationCodeConfig)(nil), // 1: bytebase.store.OAuth2AuthorizationCodeConfig+ (*OAuth2RefreshTokenConfig)(nil), // 1: bytebase.store.OAuth2RefreshTokenConfig+ (*OAuth2AuthorizationCodeConfig)(nil), // 2: bytebase.store.OAuth2AuthorizationCodeConfig}var file_store_oauth2_proto_depIdxs = []int32{0, // [0:0] is the sub-list for method output_type@@ -226,7 +291,7 @@ func file_store_oauth2_proto_init() {GoPackagePath: reflect.TypeOf(x{}).PkgPath(),RawDescriptor: unsafe.Slice(unsafe.StringData(file_store_oauth2_proto_rawDesc), len(file_store_oauth2_proto_rawDesc)),NumEnums: 0,- NumMessages: 2,+ NumMessages: 3,NumExtensions: 0,NumServices: 0,},diff --git a/backend/generated-go/store/oauth2_equal.pb.go b/backend/generated-go/store/oauth2_equal.pb.goindex 777a96bd06..22efd3174f 100644--- a/backend/generated-go/store/oauth2_equal.pb.go+++ b/backend/generated-go/store/oauth2_equal.pb.go@@ -35,6 +35,22 @@ func (x *OAuth2ClientConfig) Equal(y *OAuth2ClientConfig) bool {return true}+func (x *OAuth2RefreshTokenConfig) Equal(y *OAuth2RefreshTokenConfig) bool {+ if x == y {+ return true+ }+ if x == nil || y == nil {+ return x == nil && y == nil+ }+ if x.Resource != y.Resource {+ return false+ }+ if x.Scope != y.Scope {+ return false+ }+ return true+}+func (x *OAuth2AuthorizationCodeConfig) Equal(y *OAuth2AuthorizationCodeConfig) bool {if x == y {return truediff --git a/backend/migrator/migration/3.22/0001##oauth2_refresh_token_config.sql b/backend/migrator/migration/3.22/0001##oauth2_refresh_token_config.sqlnew file mode 100644index 0000000000..d4ab4d9a9d--- /dev/null+++ b/backend/migrator/migration/3.22/0001##oauth2_refresh_token_config.sql@@ -0,0 +1,15 @@+-- Give oauth2_refresh_token a config payload holding the consented grant state:+-- the RFC 8707 resource indicator and the OAuth2 scope, inherited from the+-- authorization code and carried forward unchanged by every refresh.+--+-- Stored as OAuth2RefreshTokenConfig (proto/store/store/oauth2.proto) rather than+-- flat columns: neither value uses a database feature (no FK, no NOT NULL, never+-- a query predicate) and both are read only from Go — the same shape as+-- oauth2_client.config and oauth2_authorization_code.config. It also lets the+-- grant gain fields later without another migration.+--+-- Defaults to '{}' so refresh tokens issued before this migration read back as an+-- empty grant, which the token endpoint treats as "no constraint to check".++ALTER TABLE oauth2_refresh_token+ ADD COLUMN IF NOT EXISTS config jsonb NOT NULL DEFAULT '{}';diff --git a/backend/migrator/migration/3.22/0001##oauth2_resource_scope_on_refresh_token.sql b/backend/migrator/migration/3.22/0001##oauth2_resource_scope_on_refresh_token.sqldeleted file mode 100644index 5063cbfde1..0000000000--- a/backend/migrator/migration/3.22/0001##oauth2_resource_scope_on_refresh_token.sql+++ /dev/null@@ -1,11 +0,0 @@--- Persist the RFC 8707 resource indicator and the consented OAuth2 scope on--- oauth2_refresh_token so a refresh carries the original grant forward--- unchanged. The authorization code keeps both in its config JSONB--- (OAuth2AuthorizationCodeConfig); the refresh token has flat columns.------ Both are nullable: grants issued before this migration have neither, and a--- client that omits the resource/scope parameters still consents successfully.--ALTER TABLE oauth2_refresh_token- ADD COLUMN IF NOT EXISTS resource text,- ADD COLUMN IF NOT EXISTS scope text;diff --git a/backend/migrator/migration/LATEST.sql b/backend/migrator/migration/LATEST.sqlindex 49e690f97c..91f4703649 100644--- a/backend/migrator/migration/LATEST.sql+++ b/backend/migrator/migration/LATEST.sql@@ -636,11 +636,10 @@ CREATE TABLE oauth2_refresh_token (-- Workspace inherited from the authorization code that originally issued-- this refresh token; preserved across refresh.workspace text REFERENCES workspace(resource_id),- -- Canonical RFC 8707 resource URI and the consented scope string, both- -- inherited from the authorization code and carried forward unchanged by- -- every refresh. Nullable: clients may omit either parameter.- resource text,- scope text,+ -- Stored as OAuth2RefreshTokenConfig (proto/store/store/oauth2.proto): the+ -- consented resource and scope, inherited from the authorization code and+ -- carried forward unchanged by every refresh.+ config jsonb NOT NULL DEFAULT '{}',expires_at timestamptz NOT NULL);diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.goindex 686d6d302b..40ab650978 100644--- a/backend/migrator/migrator_test.go+++ b/backend/migrator/migrator_test.go@@ -18,7 +18,7 @@ func TestLatestVersion(t *testing.T) {files, err := getSortedVersionedFiles()require.NoError(t, err)require.Equal(t, semver.MustParse("3.22.1"), *files[len(files)-1].version)- require.Equal(t, "migration/3.22/0001##oauth2_resource_scope_on_refresh_token.sql", files[len(files)-1].path)+ require.Equal(t, "migration/3.22/0001##oauth2_refresh_token_config.sql", files[len(files)-1].path)}func TestVersionUnique(t *testing.T) {diff --git a/backend/store/oauth2_refresh_token.go b/backend/store/oauth2_refresh_token.goindex a7cff82b0a..01ca5f5c08 100644--- a/backend/store/oauth2_refresh_token.go+++ b/backend/store/oauth2_refresh_token.go@@ -6,8 +6,11 @@ import ("time""github.com/pkg/errors"+ "google.golang.org/protobuf/encoding/protojson"+ "github.com/bytebase/bytebase/backend/common""github.com/bytebase/bytebase/backend/common/qb"+ storepb "github.com/bytebase/bytebase/backend/generated-go/store")type OAuth2RefreshTokenMessage struct {@@ -19,30 +22,28 @@ type OAuth2RefreshTokenMessage struct {// workspace_id claim. Empty only for refresh tokens created before the// 3.18.2 migration.Workspace string- // Resource is the canonical RFC 8707 resource URI the grant is bound to,- // validated against the configured external URL at consent time. Empty when- // the client omitted the resource parameter (or for pre-3.21.5 tokens).- Resource string- // Scope is the consented scope string, stored verbatim. Carried forward- // unchanged by every refresh — a refresh never widens a grant.- Scope string+ // Config is the consented grant state (resource, scope) inherited from the+ // authorization code. Carried forward unchanged by every refresh — a refresh+ // never widens a grant. Empty for tokens created before the 3.21.5 migration.+ Config *storepb.OAuth2RefreshTokenConfigExpiresAt time.Time}-// nullIfEmpty maps "" onto a NULL bind argument so the nullable oauth2 columns-// stay NULL instead of storing an empty string.-func nullIfEmpty(v string) any {- if v == "" {- return nil+func (s *Store) CreateOAuth2RefreshToken(ctx context.Context, create *OAuth2RefreshTokenMessage) (*OAuth2RefreshTokenMessage, error) {+ configBytes, err := protojson.Marshal(create.Config)+ if err != nil {+ return nil, errors.Wrap(err, "failed to marshal config")+ }++ var workspaceArg any+ if create.Workspace != "" {+ workspaceArg = create.Workspace}- return v-}-func (s *Store) CreateOAuth2RefreshToken(ctx context.Context, create *OAuth2RefreshTokenMessage) (*OAuth2RefreshTokenMessage, error) {q := qb.Q().Space(`- INSERT INTO oauth2_refresh_token (token_hash, client_id, user_email, workspace, resource, scope, expires_at)- VALUES (?, ?, ?, ?, ?, ?, ?)- `, create.TokenHash, create.ClientID, create.UserEmail, nullIfEmpty(create.Workspace), nullIfEmpty(create.Resource), nullIfEmpty(create.Scope), create.ExpiresAt)+ INSERT INTO oauth2_refresh_token (token_hash, client_id, user_email, workspace, config, expires_at)+ VALUES (?, ?, ?, ?, ?, ?)+ `, create.TokenHash, create.ClientID, create.UserEmail, workspaceArg, configBytes, create.ExpiresAt)query, args, err := q.ToSQL()if err != nil {@@ -57,7 +58,7 @@ func (s *Store) CreateOAuth2RefreshToken(ctx context.Context, create *OAuth2Refrfunc (s *Store) GetOAuth2RefreshToken(ctx context.Context, clientID, tokenHash string) (*OAuth2RefreshTokenMessage, error) {q := qb.Q().Space(`- SELECT token_hash, client_id, user_email, workspace, resource, scope, expires_at+ SELECT token_hash, client_id, user_email, workspace, config, expires_atFROM oauth2_refresh_tokenWHERE token_hash = ? AND client_id = ?`, tokenHash, clientID)@@ -68,9 +69,10 @@ func (s *Store) GetOAuth2RefreshToken(ctx context.Context, clientID, tokenHash s}msg := &OAuth2RefreshTokenMessage{}- var workspace, resource, scope sql.NullString+ var workspace sql.NullString+ var configBytes []byteif err := s.GetDB().QueryRowContext(ctx, query, args...).Scan(- &msg.TokenHash, &msg.ClientID, &msg.UserEmail, &workspace, &resource, &scope, &msg.ExpiresAt,+ &msg.TokenHash, &msg.ClientID, &msg.UserEmail, &workspace, &configBytes, &msg.ExpiresAt,); err != nil {if errors.Is(err, sql.ErrNoRows) {return nil, nil@@ -78,8 +80,11 @@ func (s *Store) GetOAuth2RefreshToken(ctx context.Context, clientID, tokenHash sreturn nil, errors.Wrap(err, "failed to get OAuth2 refresh token")}msg.Workspace = workspace.String- msg.Resource = resource.String- msg.Scope = scope.String++ msg.Config = &storepb.OAuth2RefreshTokenConfig{}+ if err := common.ProtojsonUnmarshaler.Unmarshal(configBytes, msg.Config); err != nil {+ return nil, errors.Wrap(err, "failed to unmarshal config")+ }return msg, nil}diff --git a/backend/store/oauth2_workspace_test.go b/backend/store/oauth2_workspace_test.goindex 48fe657140..7804580fa9 100644--- a/backend/store/oauth2_workspace_test.go+++ b/backend/store/oauth2_workspace_test.go@@ -127,17 +127,19 @@ func TestOAuth2WorkspaceBinding(t *testing.T) {require.Empty(t, got.Workspace)})- // The resource/scope columns (3.21.5) are the durable half of the token- // boundary: a refresh reads them back to re-issue the same grant, so a- // dropped value would silently widen or unbind the session.- t.Run("refresh token round-trips resource and scope", func(t *testing.T) {+ // The refresh token's config payload (3.21.5) is the durable half of the token+ // boundary: a refresh reads it back to re-issue the same grant, so a dropped+ // value would silently widen or unbind the session.+ t.Run("refresh token config round-trips resource and scope", func(t *testing.T) {_, err := s.CreateOAuth2RefreshToken(ctx, &store.OAuth2RefreshTokenMessage{TokenHash: "rt-hash-3",ClientID: "client-A",UserEmail: "[email protected]",Workspace: "ws-test",- Resource: "https://bb.example.com/mcp",- Scope: "mcp:read-only",+ Config: &storepb.OAuth2RefreshTokenConfig{+ Resource: "https://bb.example.com/mcp",+ Scope: "mcp:read-only",+ },ExpiresAt: time.Now().Add(30 * 24 * time.Hour),})require.NoError(t, err)@@ -145,13 +147,13 @@ func TestOAuth2WorkspaceBinding(t *testing.T) {got, err := s.GetOAuth2RefreshToken(ctx, "client-A", "rt-hash-3")require.NoError(t, err)require.NotNil(t, got)- require.Equal(t, "https://bb.example.com/mcp", got.Resource)- require.Equal(t, "mcp:read-only", got.Scope)+ require.Equal(t, "https://bb.example.com/mcp", got.Config.GetResource())+ require.Equal(t, "mcp:read-only", got.Config.GetScope())})- t.Run("refresh token with no resource or scope stays empty", func(t *testing.T) {- // Both parameters are optional, and rows written before 3.21.5 have- // NULL — either way the handler must see "" and carry "" forward.+ t.Run("refresh token with no config stays empty", func(t *testing.T) {+ // Both parameters are optional, and rows written before 3.21.5 default to+ // '{}' — either way the handler must see "" and carry "" forward._, err := s.CreateOAuth2RefreshToken(ctx, &store.OAuth2RefreshTokenMessage{TokenHash: "rt-hash-4",ClientID: "client-A",@@ -164,8 +166,8 @@ func TestOAuth2WorkspaceBinding(t *testing.T) {got, err := s.GetOAuth2RefreshToken(ctx, "client-A", "rt-hash-4")require.NoError(t, err)require.NotNil(t, got)- require.Empty(t, got.Resource)- require.Empty(t, got.Scope)+ require.Empty(t, got.Config.GetResource())+ require.Empty(t, got.Config.GetScope())})t.Run("auth code config round-trips resource and scope", func(t *testing.T) {diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.mdindex f370bf443b..bd568ee14a 100644--- a/proto/gen/grpc-doc/store/README.md+++ b/proto/gen/grpc-doc/store/README.md@@ -173,6 +173,7 @@- [store/oauth2.proto](#store_oauth2-proto)- [OAuth2AuthorizationCodeConfig](#bytebase-store-OAuth2AuthorizationCodeConfig)- [OAuth2ClientConfig](#bytebase-store-OAuth2ClientConfig)+ - [OAuth2RefreshTokenConfig](#bytebase-store-OAuth2RefreshTokenConfig)- [store/plan_check_run.proto](#store_plan_check_run-proto)- [ChangedResourceDatabase](#bytebase-store-ChangedResourceDatabase)@@ -3095,6 +3096,25 @@ ReviewSubmission records that an issue entered review.++<a name="bytebase-store-OAuth2RefreshTokenConfig"></a>++### OAuth2RefreshTokenConfig+OAuth2RefreshTokenConfig is the consented grant state carried from the+authorization code onto every refresh token issued from it, and re-issued+unchanged by each refresh. Kept as a message rather than flat columns so the+grant can gain fields without a schema migration.+++| Field | Type | Label | Description |+| ----- | ---- | ----- | ----------- |+| resource | [string](#string) | | The canonical resource URI (RFC 8707) this grant is bound to, validated at consent time against the configured external URL. Empty for clients that omit the resource parameter. |+| scope | [string](#string) | | The scope string consented to, stored verbatim. Empty means no scope was requested. |+++++diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.htmlindex bb715171a7..5056fff191 100644--- a/proto/gen/grpc-doc/store/index.html+++ b/proto/gen/grpc-doc/store/index.html@@ -856,6 +856,10 @@<a href="#bytebase.store.OAuth2ClientConfig"><span class="badge">M</span>OAuth2ClientConfig</a></li>+ <li>+ <a href="#bytebase.store.OAuth2RefreshTokenConfig"><span class="badge">M</span>OAuth2RefreshTokenConfig</a>+ </li>+@@ -9161,6 +9165,40 @@ requested. </p></td>+ <h3 id="bytebase.store.OAuth2RefreshTokenConfig">OAuth2RefreshTokenConfig</h3>+ <p>OAuth2RefreshTokenConfig is the consented grant state carried from the</p><p>authorization code onto every refresh token issued from it, and re-issued</p><p>unchanged by each refresh. Kept as a message rather than flat columns so the</p><p>grant can gain fields without a schema migration.</p>+++ <table class="field-table">+ <thead>+ <tr><td>Field</td><td>Type</td><td>Label</td><td>Description</td></tr>+ </thead>+ <tbody>++ <tr>+ <td>resource</td>+ <td><a href="#string">string</a></td>+ <td></td>+ <td><p>The canonical resource URI (RFC 8707) this grant is bound to, validated at+consent time against the configured external URL. Empty for clients that+omit the resource parameter. </p></td>+ </tr>++ <tr>+ <td>scope</td>+ <td><a href="#string">string</a></td>+ <td></td>+ <td><p>The scope string consented to, stored verbatim. Empty means no scope was+requested. </p></td>+ </tr>++ </tbody>+ </table>+++++diff --git a/proto/store/store/oauth2.proto b/proto/store/store/oauth2.protoindex 2f72403479..ee3203c6c1 100644--- a/proto/store/store/oauth2.proto+++ b/proto/store/store/oauth2.proto@@ -11,6 +11,20 @@ message OAuth2ClientConfig {string token_endpoint_auth_method = 4;}+// OAuth2RefreshTokenConfig is the consented grant state carried from the+// authorization code onto every refresh token issued from it, and re-issued+// unchanged by each refresh. Kept as a message rather than flat columns so the+// grant can gain fields without a schema migration.+message OAuth2RefreshTokenConfig {+ // The canonical resource URI (RFC 8707) this grant is bound to, validated at+ // consent time against the configured external URL. Empty for clients that+ // omit the resource parameter.+ string resource = 1;+ // The scope string consented to, stored verbatim. Empty means no scope was+ // requested.+ string scope = 2;+}+message OAuth2AuthorizationCodeConfig {string redirect_uri = 1;string code_challenge = 2;