Я предполагаю, что вы используете Mobile SDK для Android, и у вас все настроено. Во-первых, вы хотите подключиться к бассейну пользователя:
CognitoUserPool userPool = new CognitoUserPool(
context, userPoolId, clientId, clientSecret);
Затем выберите пользователя, которого вы хотите проверить подлинность:
CognitoUser user = userPool.getUser(userId);
Затем написать authentication handler. Cognito будет звонить в ваш код, когда (если) ему нужно имя пользователя и пароль, а не вы его называете.
AuthenticationHandler handler = new AuthenticationHandler {
@Override
public void onSuccess(CognitoUserSession userSession) {
// Authentication was successful, the "userSession" will have the current valid tokens
}
@Override
public void getAuthenticationDetails(final AuthenticationContinuation continuation, final String userID) {
// User authentication details, userId and password are required to continue.
// Use the "continuation" object to pass the user authentication details
// After the user authentication details are available, wrap them in an AuthenticationDetails class
// Along with userId and password, parameters for user pools for Lambda can be passed here
// The validation parameters "validationParameters" are passed in as a Map<String, String>
AuthenticationDetails authDetails = new AuthenticationDetails(userId, password, validationParameters);
// Now allow the authentication to continue
continuation.setAuthenticationDetails(authDetails);
continuation.continueTask();
}
/* Handle 2FA, challenges, etc as needed */
};
Наконец, попробуйте получить новую сессию и дать обработчик.
user.getSession(handler);
Если все пойдет хорошо, вы должны иметь сеанс с действительными токенами.
Этот пример основан на developer guide, в котором также есть примеры для регистрации новых пользователей, выхода из системы и т. Д.
Извините, я не использую Mobile SDK. Я использую Java SDK. – bdparrish