AWS Cognito 身份服务提供商似乎将访问令牌存储在本地存储中

问题描述 投票:0回答:1

我们正在开发一个使用 Angular 前端网站的应用程序。我们正在使用 AWS Appsync API 作为后端,这需要放大登录

它工作正常,但我们注意到 Cognito 提供程序将 Cognito 详细信息和访问令牌存储在浏览器本地存储中。这是我们在 Chrome 中使用 F12 并检查本地存储所看到的。如何删除这个本地存储或者有什么方法可以对其进行加密。

angular local-storage aws-amplify aws-appsync
1个回答
0
投票

您可以使用自定义存储将其存储在您认为最好的地方或以安全的方式(react-secure-storage?)

https://docs.amplify.aws/javascript/build-a-backend/auth/manage-user-session/

class MyCustomStorage implements KeyValueStorageInterface {
    storageObject: Record<string, string> = {};   
    
    async setItem(key: string, value: string): Promise<void> {
        this.storageObject[key] = value;   
    }   
    async getItem(key: string): Promise<string | null> {
        return this.storageObject[key];   
    }   
    async removeItem(key: string): Promise<void> {
        delete this.storageObject[key];   
    }   
    async clear(): Promise<void> {
        this.storageObject = {};   
    } 
}

Amplify.configure({   Auth: authConfig });
    
cognitoUserPoolsTokenProvider.setKeyValueStorage(new MyCustomStorage());
© www.soinside.com 2019 - 2024. All rights reserved.