Stf*_*f_F 6 amazon-web-services amazon-iam amazon-cognito aws-sdk firebase-authentication
我在使用 Firebase 作为 Open ID Connect 提供商时遇到了困难。您能否进一步描述一下您在完成这项工作之前和之后所经历的步骤?
有关信息,以下是我到目前为止所做的操作:在 AWS 控制台中:
1 - 创建 IAM 身份提供商 ( OpenID Connect ) 并用作受众的securetoken.google.com/<FIREBASE_PROJECT_ID>
URL<FIREBASE_PROJECT_ID>
2 - 手动检查指纹(它与 AWS 生成的指纹匹配)
3 - 创建具有访问所需服务权限的角色
4 - 在 Cognito 中创建了一个身份池,并在“经过身份验证的角色”下拉列表中选择了我新创建的角色
5 - 在身份验证提供程序 > OpenID 类别下选择我的身份提供程序(因此格式为):securetoken.google.com/<FIREBASE_PROJECT_ID>
在我的代码(我使用 Vue.js)中,以下是我经历的逻辑步骤:
导入/设置AWS SDK
调用 Firebase 身份验证服务
问题是我不断收到“配置中缺少凭据”错误。
代码:
import axios from 'axios';
const AWS = require('aws-sdk');
AWS.config.region = 'eu-west-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'MY_COGNITO_POOL_ID',
});
export default {
name: 'My Vue.js component name',
data() {
return {
email: '',
password: '',
msg: '',
};
},
methods: {
submit() {
axios
.post(
'https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=MY_KEY',
{
email: this.email,
password: password,
returnSecureToken: true,
},
)
.then((res) => {
// stores tokens locally
localStorage.setItem('jwt', JSON.stringify(res.data));
const cognitoidentity = new AWS.CognitoIdentity();
const params = {
IdentityPoolId: 'MY_COGNITO_POOL_ID',
Logins: {
'securetoken.google.com/<PROJECT_ID>': res.data.idToken,
},
IdentityId: null,
TokenDuration: 3600,
};
cognitoidentity.getOpenIdTokenForDeveloperIdentity(params, (err, data) => {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
});
},
},
};
Run Code Online (Sandbox Code Playgroud)
以下是我迄今为止在尝试完成这项工作时使用的资源:
使用 Firebase OpenID Connect 提供商作为 AWS IAM 身份提供商
https://github.com/aws/amazon-cognito-identity-js/blob/master/examples/babel-webpack/src/main.jsx
http://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html
https://aws.amazon.com/blogs/mobile/understanding-amazon-cognito-authentication/
尝试设置登录映射,即CognitoIdentityCredentials
对象中的 firebase 令牌。请参阅此文档。
AWS.config.credentials = 新 AWS.CognitoIdentityCredentials({ IdentityPoolId: 'MY_COGNITO_POOL_ID', 登录:{ 'securetoken.google.com/': } });
如果上述步骤不起作用(应该起作用),请在初始化 Cognito 客户端时将凭据作为选项传递。请参阅此文档以了解使用 CognitoIdentity 构造函数时可用的选项。
const cognitoidentity = new AWS.CognitoIdentity({credentials: AWS.config.credentials});
如果仍然收到错误,请尝试在调用 get() 方法后在控制台中记录凭据对象。理想情况下,它应该有临时凭证(accessKey、secretKey 和 sessionToken)
归档时间: |
|
查看次数: |
3263 次 |
最近记录: |