質問編集履歴
4
誤字の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -88,7 +88,7 @@
|
|
88
88
|
|
89
89
|
|
90
90
|
|
91
|
-
次に、ログイン判定を行うために、セッション情報を取得したい
|
91
|
+
次に、ログイン判定を行うために、セッション情報を取得したいです.
|
92
92
|
|
93
93
|
Google認証を行なった場合、以下のコードを実行すると、変数cognitoUserでnullが返ってきます.
|
94
94
|
|
3
問題が改善したので、別の問題の追記
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Googleを
|
1
|
+
Googleを用いたCognito認証のセッション情報の取得
|
test
CHANGED
@@ -1,28 +1,14 @@
|
|
1
1
|
### 実現したいこと
|
2
2
|
|
3
|
-
Googleアカウント情報を使って、ログイン認証したい。
|
3
|
+
Googleアカウント情報を使って、ログイン認証したい。そのセッション情報を取得したい。
|
4
|
-
|
5
|
-
その際に、認証トークンをCognitoに渡したい
|
6
4
|
|
7
5
|
|
8
6
|
|
9
7
|
### 現状
|
10
8
|
|
11
|
-
|
9
|
+
GoogleとCognitoを用いて、ログイン認証することに成功しました.
|
12
10
|
|
13
|
-
<div class="sns_wrapper">
|
14
|
-
|
15
|
-
<div id="gSignInWrapper" v-on:click="gSignIn">
|
16
|
-
|
17
|
-
<span class="icon"></span>
|
18
|
-
|
19
|
-
<span class="buttonText">Googleでログイン</span>
|
20
|
-
|
21
|
-
|
11
|
+
そのコードを以下に示します.
|
22
|
-
|
23
|
-
</div>
|
24
|
-
|
25
|
-
```
|
26
12
|
|
27
13
|
|
28
14
|
|
@@ -94,13 +80,71 @@
|
|
94
80
|
|
95
81
|
|
96
82
|
|
97
|
-
|
83
|
+
以下のように、フェデレーティッドアイデンティティのダッシュボードで、ログイン出来ていることを確認しました.
|
98
84
|
|
99
|
-
|
85
|
+
![イメージ説明](cc4b5477db72a60c31469b3a00a1ff94.png)
|
100
86
|
|
101
87
|
|
102
88
|
|
89
|
+
|
90
|
+
|
91
|
+
次に、ログイン判定を行うために、セッション情報を取得したいのです.
|
92
|
+
|
93
|
+
Google認証を行なった場合、以下のコードを実行すると、変数cognitoUserでnullが返ってきます.
|
94
|
+
|
95
|
+
(通常のCognito認証の場合は、上手くセッション情報を取得できています)
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
var userPool = new AmazonCognitoIdentity.CognitoUserPool({
|
102
|
+
|
103
|
+
UserPoolId: userPoolId,
|
104
|
+
|
105
|
+
ClientId: clientId
|
106
|
+
|
107
|
+
});
|
108
|
+
|
103
|
-
|
109
|
+
var cognitoUser = userPool.getCurrentUser();
|
110
|
+
|
111
|
+
console.log(cognitoUser);
|
112
|
+
|
113
|
+
if (cognitoUser != null) {
|
114
|
+
|
115
|
+
cognitoUser.getSession(function(err, session) {
|
116
|
+
|
117
|
+
if (err) {
|
118
|
+
|
119
|
+
sessionErr();
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
|
124
|
+
|
125
|
+
RoleArn: "arn:aws:iam::[AccountID]:role/[AuthRole]",
|
126
|
+
|
127
|
+
IdentityPoolId: identityPoolId,
|
128
|
+
|
129
|
+
Logins: {
|
130
|
+
|
131
|
+
"cognito-idp.ap-northeast-1.amazonaws.com/[userPoolId]": session.getIdToken().getJwtToken(),
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
});
|
136
|
+
|
137
|
+
});
|
138
|
+
|
139
|
+
return cognitoUser;
|
140
|
+
|
141
|
+
} else {
|
142
|
+
|
143
|
+
sessionErr();
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
```
|
104
148
|
|
105
149
|
|
106
150
|
|
2
コードの編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,7 +58,7 @@
|
|
58
58
|
|
59
59
|
Logins: {
|
60
60
|
|
61
|
-
"accounts.google.com": googleUser
|
61
|
+
"accounts.google.com": googleUser.getAuthResponse().id_token
|
62
62
|
|
63
63
|
}
|
64
64
|
|
@@ -94,7 +94,7 @@
|
|
94
94
|
|
95
95
|
|
96
96
|
|
97
|
-
上記の実行結果で下記の内容が返ってきました。認証トークンは "id_token" に入っていると思って
|
97
|
+
上記の実行結果で下記の内容が返ってきました。認証トークンは "id_token" に入っていると思っており、その情報をCognitoに渡しているつもりなのですが、セッション情報が取得できていません.
|
98
98
|
|
99
99
|
(フェデレーティッドアイデンティティのダッシュボードを見ても、Googleでのサインインは出来ていないようです.)
|
100
100
|
|
1
内容の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -101,3 +101,7 @@
|
|
101
101
|
|
102
102
|
|
103
103
|
![トークン結果](482896dfb6eeadec0d1fc0701e7e5dde.png)
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
上記の間違っている点や、他の方法等がありましたら、ぜひご教授お願いします.
|