Preview tokens 8: New structure for preview tokens #6836
Merged
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.
Description
Summary of changes & Reasoning
Additional context
PR 9 will build on the URI-based tokens to implement preview tokens for custom blueprint
preview
options.Coverage: One line in the
previewTokenFromUrl
method is not tested by this PR. This is because this case is prepared for PR 9 and will be tested there.Changelog
Enhancements
Breaking changes
content.salt
option will no longer receive a model when generating a salt for preview authentication tokens of drafts and versions as those tokens are now only based on the URI. Thus the salt callback instead receivesnull
and is expected to return a fixed model-independent salt in this case. When generating a salt for a file media token, the file object is still passed as model.Docs
Replacing https://getkirby.com/docs/reference/system/options/content#salt-for-drafts-and-media-files:
Salt for page previews and media files
URLs of page previews and media files contain a hashed token that should be hard to guess. The tokens are based on the page URI or file ID and are authenticated with a salt value. In the way Kirby uses this salt value, it should ideally be a secret. By default, Kirby uses the filesystem path of the content folder. You can define your own salt that will be used instead:
You can also dynamically generate a salt based on the model that needs a token:
<since v="5.0.0">
The
$model
value is set to theFile
object when generating a media token for a file. For page preview tokens,$model
is always passed asnull
. Your callback should return a fixed model-independent salt in this case.</since>
Ready?
For review team
Add lab and/or sandbox examples (wherever helpful)