javascript - 使用 aws-amplify 时如何将 cookie 过期时间设置为 30 分钟?
问题描述
以下代码是放大身份验证的手动配置,我只想设置expires
为cookieStorage
30 分钟而不是 365 天。
import Amplify from 'aws-amplify';
Amplify.configure({
Auth: {
// REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
// REQUIRED - Amazon Cognito Region
region: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito Federated Identity Pool Region
// Required only if it's different from Amazon Cognito Region
identityPoolRegion: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'XX-XXXX-X_abcd1234',
// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',
// OPTIONAL - Enforce user authentication prior to accessing AWS resources or not
mandatorySignIn: false,
// OPTIONAL - Configuration for cookie storage
cookieStorage: {
// REQUIRED - Cookie domain (only required if cookieStorage is provided)
domain: '.yourdomain.com',
// OPTIONAL - Cookie path
path: '/',
// OPTIONAL - Cookie expiration in days
expires: 365,
// OPTIONAL - Cookie secure flag
secure: true
},
// OPTIONAL - customized storage object
storage: new MyStorage(),
// OPTIONAL - Manually set the authentication flow type. Default is 'USER_SRP_AUTH'
authenticationFlowType: 'USER_PASSWORD_AUTH'
}
});
解决方案
好问题!
我认为您只能将天设置为单位,而不能设置其他单位。
从文档:
The CookieStorage object receives a map (data) in its constructor that
may have these values:
data.domain Cookies domain (mandatory)
data.path Cookies path (default: '/')
data.expires Cookie expiration (in days, default: 365)
data.secure Cookie secure flag (default: true)
https://github.com/aws-amplify/amplify-js/tree/master/packages/amazon-cognito-identity-js
推荐阅读
- flutter - 从数据库读取数据到 TextFormField
- python - 如何检查我的数据集的预测
- python - 如何循环 3 个分类为“正”、“负”和“中性”的熊猫数据帧并列出它们?
- assembly - 尝试在 MASM32 (LNK1120) 中做一个简单的程序
- php - 为什么我没有得到相同的结果?
- c# - 在所有用户控件中将任何字符全局转换为大写
- data-structures - 如何在一个特征的函数中发送不同的结构?
- java - 如何在 mule anypoint studio 中处理来自 gmail 服务器的 pop3 电子邮件
- r - 在 R 中查找和替换某些值
- google-apps-script - 在 Google 表格中,有没有办法每次都获取在同一个单元格中输入的数据总和?