Signs and timestamps a cookie so it cannot be forged. You must specify the ``cookie_secret`` setting in your Application to use this method. It should be a long, random sequence of bytes to be used as the HMAC secret for the signature. To read a cookie set with this
(
self,
name: str,
value: Union[str, bytes],
expires_days: Optional[float] = 30,
version: Optional[int] = None,
**kwargs: Any
)
| 685 | self.clear_cookie(name, path=path, domain=domain) |
| 686 | |
| 687 | def set_secure_cookie( |
| 688 | self, |
| 689 | name: str, |
| 690 | value: Union[str, bytes], |
| 691 | expires_days: Optional[float] = 30, |
| 692 | version: Optional[int] = None, |
| 693 | **kwargs: Any |
| 694 | ) -> None: |
| 695 | """Signs and timestamps a cookie so it cannot be forged. |
| 696 | |
| 697 | You must specify the ``cookie_secret`` setting in your Application |
| 698 | to use this method. It should be a long, random sequence of bytes |
| 699 | to be used as the HMAC secret for the signature. |
| 700 | |
| 701 | To read a cookie set with this method, use `get_secure_cookie()`. |
| 702 | |
| 703 | Note that the ``expires_days`` parameter sets the lifetime of the |
| 704 | cookie in the browser, but is independent of the ``max_age_days`` |
| 705 | parameter to `get_secure_cookie`. |
| 706 | A value of None limits the lifetime to the current browser session. |
| 707 | |
| 708 | Secure cookies may contain arbitrary byte values, not just unicode |
| 709 | strings (unlike regular cookies) |
| 710 | |
| 711 | Similar to `set_cookie`, the effect of this method will not be |
| 712 | seen until the following request. |
| 713 | |
| 714 | .. versionchanged:: 3.2.1 |
| 715 | |
| 716 | Added the ``version`` argument. Introduced cookie version 2 |
| 717 | and made it the default. |
| 718 | """ |
| 719 | self.set_cookie( |
| 720 | name, |
| 721 | self.create_signed_value(name, value, version=version), |
| 722 | expires_days=expires_days, |
| 723 | **kwargs |
| 724 | ) |
| 725 | |
| 726 | def create_signed_value( |
| 727 | self, name: str, value: Union[str, bytes], version: Optional[int] = None |