質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

0回答

2104閲覧

[vue.js]AWSのcognitoで取得したクレデンシャル情報をローカルストレージに保管する方法

noz_awsinf_sp

総合スコア62

Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2020/05/28 06:57

https://github.com/aws-amplify/amplify-js/tree/master/packages/amazon-cognito-identity-js

Vue.jsで作成したwebアプリ内で、上記のAWSSDKを利用して、AWSの認証情報を取得することは実装できたのですが、画面リロードをすると、おそらくAWS.config.credentialsインスタンスが消えてしまい
クレデンシャルがないとエラーがでます。

Vuexのストアを使って、ローカルストレージに保存しようとしているのですが、
stateでAWS.config.credentialsを管理することは可能でしょうか?
単純に下記のような記述をすると「Unexpected token, expected "," 」とでるので
キーバリューのような形式にする必要がなるのでしょうか?

state: { AWS.config.credentials },

↓cognito認証の例

import * as AWS from 'aws-sdk/global'; var authenticationData = { Username: 'username', Password: 'password', }; var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails( authenticationData ); var poolData = { UserPoolId: '...', // Your user pool id here ClientId: '...', // Your client id here }; var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData); var userData = { Username: 'username', Pool: userPool, }; var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData); cognitoUser.authenticateUser(authenticationDetails, { onSuccess: function(result) { var accessToken = result.getAccessToken().getJwtToken(); //POTENTIAL: Region needs to be set if not already set previously elsewhere. AWS.config.region = '<region>'; AWS.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: '...', // your identity pool id here Logins: { // Change the key below according to the specific region your user pool is in. 'cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>': result .getIdToken() .getJwtToken(), }, }); //refreshes credentials using AWS.CognitoIdentity.getCredentialsForIdentity() AWS.config.credentials.refresh(error => { if (error) { console.error(error); } else { // Instantiate aws sdk service objects now that the credentials have been updated. // example: var s3 = new AWS.S3(); console.log('Successfully logged!'); } }); }, onFailure: function(err) { alert(err.message || JSON.stringify(err)); }, });

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問