问题描述
我的目标是使用SocialProvider登录创建基于Cognito的身份验证流程,该流程既支持移动原生体验,也支持网络体验。
例如-我想在iOS设备上提供设备原生的SignInWithApple体验,但在浏览器上仍支持使用AppleID登录。无论使用哪种身份验证流,我都希望将经过身份验证的用户视为同一用户。
我的两种流程都如下所述;但我不知道如何将这两个分别创建的身份关联在一起,并将其视为一个用户(最好通过AppSync $ context.identity访问)。我感觉到我正在接近这个错误-非常感谢收到任何指针。
我的方法
对于设备本机:会生成auth令牌,然后将其传递给Auth.federatedSignIn(),以对IdentityPool进行身份验证。
NB:在本机场景中,我使用的是CognitoIdentityPool身份验证,而不是CognitoUserPool,因为尽我所能告诉我不可能将提供者令牌直接传递给CognitoUserPool。而是必须使用托管的UI(我不想这样做,因为与设备本机体验相比,浏览器界面的用户体验较差,尤其是对于SignInWithApple)。
对于网络:使用Auth.federateSignIn()调用Cognito托管的UI,这会针对UserPool进行身份验证,然后在IdentityPool中创建一个独特的身份。
环境
Ionic Framework : @ionic/angular 5.3.3
@angular : 9.1.12
@capacitor/core : 2.4.2
aws-amplify : 3.0.25
Cognito IdentityPool
Cognito UserPool
AppSync
本机(CognitoIdentityPool)
const { SignInWithApple } = Plugins;
const res: ResponseSignInWithApplePlugin = await SignInWithApple.Authorize();
const decoded = jwt_decode<any>(res.response.identityToken);
const credentials = await Auth.federatedSignIn(
'appleid.apple.com',{
token: res.response.identityToken,expires_at: decoded?.exp * 1000 + new Date().getTime(),},{
name: `${res.response.givenname} ${res.response.familyName}`,email: decoded?.email,}
);
网络/ CognitoUserPool(通过托管UI)
await this.federatedSignIn(CognitoHostedUIIdentityProvider.Apple);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)