【发布时间】:2017-11-13 02:10:24
【问题描述】:
我很难将 Firebase 用作 Open ID Connect 提供程序。 您能否进一步描述您在完成这项工作之前和之后所经历的步骤?
有关信息,这是我迄今为止所做的: 在 AWS 控制台中:
1 - 创建一个 IAM 身份提供商 ( OpenID Connect ) 并使用 securetoken.google.com/<FIREBASE_PROJECT_ID> 作为 URL,<FIREBASE_PROJECT_ID>for Audience
2 - 手动检查指纹(与 AWS 生成的指纹匹配)
3 - 创建一个具有访问所需服务权限的角色
4 - 在 Cognito 中创建了一个身份池,并在“已验证角色”下拉列表中选择了我新创建的角色
5 - 在身份验证提供者 > OpenID 类别下选择了我的身份提供者(因此格式为):securetoken.google.com/<FIREBASE_PROJECT_ID>
在我的代码中(我使用的是 Vue.js),这是我经历的合乎逻辑的步骤:
导入/设置 AWS SDK
调用 Firebase 身份验证服务
- 创建新的 CognitoIdentity
- 使用 getOpenIdTokenForDeveloperIdentity 并推送从 Firebase 收到的 tokenID
问题是我不断收到“配置中缺少凭据”错误。
代码:
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
});
});
},
},
};
以下是迄今为止我在尝试完成这项工作时使用的资源:
Using Firebase OpenID Connect provider as AWS IAM Identity Provider
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/
【问题讨论】:
-
您是否必须在 Firebase 项目方面进行任何配置才能使其正常工作?似乎,鉴于 Firebase 项目 ID、用户的电子邮件和密码,他们可以在 Firebase 项目所有者不知道的情况下使用此方法。
标签: amazon-web-services firebase-authentication aws-sdk amazon-cognito amazon-iam