【问题标题】:How to set the cookie expiration time to 30 minutes when using aws-amplify?使用 aws-amplify 时如何将 cookie 过期时间设置为 30 分钟?
【发布时间】:2018-12-05 18:38:24
【问题描述】:

以下代码是放大认证的手动配置,我只想将cookieStorage下的expires设置为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'
        }
    });

【问题讨论】:

    标签: javascript reactjs aws-amplify


    【解决方案1】:

    好问题!

    我认为您只能将天设置为单位,而不能设置其他单位。

    来自文档:

    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

    【讨论】:

      【解决方案2】:

      使用一天的一小部分。 0.5 将是 12 小时。 30 分钟约为 0.02。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-17
        • 2014-05-03
        • 2011-07-30
        • 2010-12-22
        • 1970-01-01
        • 1970-01-01
        • 2022-11-27
        • 1970-01-01
        相关资源
        最近更新 更多