AWS 移动自定义登录
AWS Mobile Custom SignIn
我已经创建了一个与 Google Firebase 配合良好的自定义登录,但该应用程序需要在中国使用,因此 Google 不行。我已通读 AWS Cognito 文档,但似乎没有类似于 Firebase 的身份验证方法,我可以在其中使用自定义登录 UI.
只需使用电子邮件和密码进行简单登录即可,没有注册功能。这可能与 Android 的 AWS Cognitio 相关吗?
感谢您的帮助。
您可以使用适用于 Android - Cognito 身份提供商的 AWS SDK 将登录功能添加到您的应用程序。
将以下依赖项导入 build.gradle 文件并执行 gradle 同步:
implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.6.25'
在您的应用中添加以下代码:
// Callback handler for the sign-in process
AuthenticationHandler authenticationHandler = new AuthenticationHandler() {
@Override
public void onSuccess(CognitoUserSession cognitoUserSession) {
// Sign-in was successful, cognitoUserSession will contain tokens for the user
}
@Override
public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId) {
// The API needs user sign-in credentials to continue
AuthenticationDetails authenticationDetails = new AuthenticationDetails(userId, password, null);
// Pass the user sign-in credentials to the continuation
authenticationContinuation.setAuthenticationDetails(authenticationDetails);
// Allow the sign-in to continue
authenticationContinuation.continueTask();
}
@Override
public void getMFACode(MultiFactorAuthenticationContinuation multiFactorAuthenticationContinuation) {
// Multi-factor authentication is required; get the verification code from user
multiFactorAuthenticationContinuation.setMfaCode(mfaVerificationCode);
// Allow the sign-in process to continue
multiFactorAuthenticationContinuation.continueTask();
}
@Override
public void onFailure(Exception exception) {
// Sign-in failed, check exception for the cause
}
};
// Sign in the user
cognitoUser.getSessionInBackground(authenticationHandler);
您可以查看示例应用程序:https://github.com/awslabs/aws-sdk-android-samples/tree/master/AmazonCognitoYourUserPoolsDemo
我已经创建了一个与 Google Firebase 配合良好的自定义登录,但该应用程序需要在中国使用,因此 Google 不行。我已通读 AWS Cognito 文档,但似乎没有类似于 Firebase 的身份验证方法,我可以在其中使用自定义登录 UI.
只需使用电子邮件和密码进行简单登录即可,没有注册功能。这可能与 Android 的 AWS Cognitio 相关吗?
感谢您的帮助。
您可以使用适用于 Android - Cognito 身份提供商的 AWS SDK 将登录功能添加到您的应用程序。
将以下依赖项导入 build.gradle 文件并执行 gradle 同步:
implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.6.25'
在您的应用中添加以下代码:
// Callback handler for the sign-in process
AuthenticationHandler authenticationHandler = new AuthenticationHandler() {
@Override
public void onSuccess(CognitoUserSession cognitoUserSession) {
// Sign-in was successful, cognitoUserSession will contain tokens for the user
}
@Override
public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId) {
// The API needs user sign-in credentials to continue
AuthenticationDetails authenticationDetails = new AuthenticationDetails(userId, password, null);
// Pass the user sign-in credentials to the continuation
authenticationContinuation.setAuthenticationDetails(authenticationDetails);
// Allow the sign-in to continue
authenticationContinuation.continueTask();
}
@Override
public void getMFACode(MultiFactorAuthenticationContinuation multiFactorAuthenticationContinuation) {
// Multi-factor authentication is required; get the verification code from user
multiFactorAuthenticationContinuation.setMfaCode(mfaVerificationCode);
// Allow the sign-in process to continue
multiFactorAuthenticationContinuation.continueTask();
}
@Override
public void onFailure(Exception exception) {
// Sign-in failed, check exception for the cause
}
};
// Sign in the user
cognitoUser.getSessionInBackground(authenticationHandler);
您可以查看示例应用程序:https://github.com/awslabs/aws-sdk-android-samples/tree/master/AmazonCognitoYourUserPoolsDemo