Add public key token storage for non-revocable publishable keys #8
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.
Summary
public: trueoption to key_types config that stores plaintext token in metadata for later viewingpublic: trueANDrevocable: falseThe Problem
Non-revocable keys create a lockout scenario: if a user creates a publishable key, doesn't copy it immediately, and closes the page—they're stuck forever. They can't recover the token (we only store the hash) and can't delete the key to create a new one (it's non-revocable). With
limit: 1, they'd be permanently locked out.The Solution
For publishable keys designed to be embedded in client apps, there's no security benefit to hiding the token—they're meant to be public! (Stripe lets you view publishable keys anytime.) The
public: trueoption stores the token in metadata so users can view it again.Security
Token storage requires BOTH conditions:
public: truein configrevocable: falsein configThis ensures secret keys are NEVER stored, even if misconfigured. Added 10 dedicated security tests verifying this.
Changes
lib/api_keys/models/api_key.rbpublic_key_type?,viewable_tokenmethods + storage logicapp/views/api_keys/keys/_key_row.html.erblib/api_keys/configuration.rbpublicoption in YARD docslib/generators/api_keys/templates/initializer.rbpublicoption with security warningREADME.mdtest/key_types_test.rbTest plan
public: truedo NOT store token🤖 Generated with Claude Code