fix: persist MCP OAuth signing/encryption keys in the database - #347
Open
JeyDim wants to merge 1 commit into
Open
fix: persist MCP OAuth signing/encryption keys in the database#347JeyDim wants to merge 1 commit into
JeyDim wants to merge 1 commit into
Conversation
impworks
requested changes
Aug 6, 2026
|
|
||
| // In production, supply the server's signing/encryption credentials from persistent keys | ||
| // stored in the database (development relies on the framework's development certificates). | ||
| if (Environment.EnvironmentName != "Development") |
Owner
There was a problem hiding this comment.
Возможно, есть смысл использовать одинаковый подход в обоих случаях - и в проде, и во время разработки?
| { | ||
| // Another instance generated the key concurrently: discard ours and reuse the stored one. | ||
| db.ChangeTracker.Clear(); | ||
| var stored = db.OAuthKeys.First(x => x.Purpose == purpose); |
Owner
There was a problem hiding this comment.
Код с загрузкой значения из базы по purpose, декодированием из base64 и загрузкой повторяется дважды - его можно вынести в локальную функцию
| /// </summary> | ||
| public class OAuthKeyManager(IServiceScopeFactory scopeFactory) | ||
| { | ||
| private const string SigningPurpose = "Signing"; |
Owner
There was a problem hiding this comment.
Думаю что эти штуки можно было бы сделать enum'ом - чуть более строго типизировано, к тому же тогда PK в таблице был бы числовым. Но не принципиально.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
В production среде сервер OpenIddict использовал временные ключи подписи и шифрования, которые генерировались заново при каждом запуске.
Теперь ключи генерируются один раз и хранятся в базе данных (таблица OAuthKeys), а затем загружаются при последующих запусках, так что выданные токены остаются действительными при перезапусках.
Разработка по-прежнему опирается на сертификаты разработки фреймворка, которые уже сохраняются для каждого пользователя.
Closes #344.