好的,经过多次试验和错误,我尝试了解决方案路径 2,它奏效了。
所以我的身份验证流程如下所示:
发送 POST 请求(使用 cybress.request)到
https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword
,并解析响应。创建一个对象:response1 = response.body
发送 POST 请求(使用 cybress.request)到
https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo
,使用来自 prev 请求的 idToken。创建一个对象:user = response2.body.users[0];
将对象中的响应与以下属性相结合:
const authObject = {
uid: response1.localId,
displayName: response1.displayName,
photoURL: null,
email: response1.email,
phoneNumber: null,
isAnonymous: false,
providerData: [
{
uid: response1.email,
displayName: response1.displayName,
photoURL: null,
email: body.email,
phoneNumber: null,
providerId: 'password'
}
],
'apiKey': apiKey,
'appName': '[DEFAULT]',
'authDomain': '<name of firebase domain>',
'stsTokenManager': {
'apiKey': apiKey,
'refreshToken': response1.refreshToken,
'accessToken': response1.idToken,
'expirationTime': user.lastLoginAt + Number(response1.expiresIn)
},
'redirectEventId': null,
'lastLoginAt': user.lastLoginAt,
'createdAt': user.createdAt
};
然后在 cybress 中,我只是将这个对象保存在本地存储中,在 before 钩子中:localStorage.setItem(
firebase:authUser:${apiKey}:[DEFAULT], authObject);
也许不完美,但它解决了问题。如果您对代码感兴趣,请告诉我,如果您对如何构建“authObject”有任何了解,或者以其他方式解决此问题。