use of com.okta.authn.sdk.resource.AuthenticationResponse in project okta-oidc-android by okta.
the class SampleActivity method onSignIn.
@Override
public void onSignIn(String username, String password) {
mSignInDialog.dismiss();
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
mTvStatus.setText("Invalid username or password");
return;
}
showNetworkProgress(true);
mExecutor.submit(() -> {
try {
if (mAuthenticationClient == null) {
return;
}
mAuthenticationClient.authenticate(username, password.toCharArray(), null, new AuthenticationStateHandlerAdapter() {
@Override
public void handleUnknown(AuthenticationResponse authenticationResponse) {
SampleActivity.this.runOnUiThread(() -> {
showNetworkProgress(false);
mTvStatus.setText(authenticationResponse.getStatus().name());
});
}
@Override
public void handleLockedOut(AuthenticationResponse lockedOut) {
SampleActivity.this.runOnUiThread(() -> {
showNetworkProgress(false);
mTvStatus.setText("Account locked out");
});
}
@Override
public void handleSuccess(AuthenticationResponse successResponse) {
String sessionToken = successResponse.getSessionToken();
mAuthClient.signIn(sessionToken, mPayload, new RequestCallback<Result, AuthorizationException>() {
@Override
public void onSuccess(@NonNull Result result) {
mTvStatus.setText("authentication authorized");
mIsSessionSignIn = true;
showAuthenticatedMode();
showNetworkProgress(false);
}
@Override
public void onError(String error, AuthorizationException exception) {
mTvStatus.setText(error);
}
});
}
});
} catch (AuthenticationException e) {
Log.e(TAG, Log.getStackTraceString(e));
runOnUiThread(() -> {
showNetworkProgress(false);
mTvStatus.setText(e.getMessage());
});
}
});
}
use of com.okta.authn.sdk.resource.AuthenticationResponse in project okta-auth-java by okta.
the class LoginController method handlePost.
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ModelAndView handlePost(@RequestParam("username") final String username, @RequestParam("password") final String password) {
final ModelAndView modelAndView = new ModelAndView("home");
AuthenticationResponse authenticationResponse;
try {
authenticationResponse = authenticationClient.authenticate(username, password.toCharArray(), null, ignoringStateHandler);
// handle factors, if any
if (authenticationResponse != null && !CollectionUtils.isEmpty(authenticationResponse.getFactors())) {
return AuthHelper.proceedToVerifyView(authenticationResponse, authenticationClient, ignoringStateHandler);
}
} catch (final AuthenticationException e) {
logger.error("Authentication Error - Status: {}, Code: {}, Message: {}", e.getStatus(), e.getCode(), e.getMessage());
modelAndView.addObject("error", e.getStatus() + ":" + e.getCode() + ":" + e.getMessage());
return modelAndView;
}
modelAndView.addObject("authenticationResponse", authenticationResponse);
return modelAndView;
}
use of com.okta.authn.sdk.resource.AuthenticationResponse in project okta-auth-java by okta.
the class AuthHelper method proceedToVerifyView.
public static ModelAndView proceedToVerifyView(final AuthenticationResponse authenticationResponse, final AuthenticationClient authenticationClient, final AuthenticationStateHandler ignoringStateHandler) throws AuthenticationException {
final String factorId = authenticationResponse.getFactors().get(0).getId();
final FactorType factorType = authenticationResponse.getFactors().get(0).getType();
final String stateToken = authenticationResponse.getStateToken();
// we only support Email factor for sample purpose
if (factorType == FactorType.EMAIL) {
AuthenticationResponse authResponse = authenticationClient.verifyFactor(factorId, stateToken, ignoringStateHandler);
final ModelAndView emailAuthView = new ModelAndView("verify-email-authenticator");
emailAuthView.addObject("authenticationResponse", authResponse);
return emailAuthView;
} else {
final ModelAndView errorView = new ModelAndView("home");
errorView.addObject("error", "Factor type " + factorType + " + is not supported in this sample yet");
return errorView;
}
}
use of com.okta.authn.sdk.resource.AuthenticationResponse in project okta-auth-java by okta.
the class ForgotPasswordController method handleChangePasswordPost.
@RequestMapping(value = "/change-password", method = RequestMethod.POST)
public ModelAndView handleChangePasswordPost(@RequestParam("newPassword") final String newPassword, @RequestParam("stateToken") final String stateToken) {
final ModelAndView modelAndView = new ModelAndView("home");
final AuthenticationResponse authenticationResponse;
try {
authenticationResponse = authenticationClient.resetPassword(newPassword.toCharArray(), stateToken, ignoringStateHandler);
} catch (final AuthenticationException e) {
logger.error("Reset Password Error - Status: {}, Code: {}, Message: {}", e.getStatus(), e.getCode(), e.getMessage());
final ModelAndView errorView = new ModelAndView("change-password");
errorView.addObject("error", e.getStatus() + ":" + e.getCode() + ":" + e.getMessage());
return errorView;
}
logger.info("Reset Password Status: {}", authenticationResponse.getStatus());
modelAndView.addObject("authenticationResponse", authenticationResponse);
return modelAndView;
}
use of com.okta.authn.sdk.resource.AuthenticationResponse in project okta-auth-java by okta.
the class ForgotPasswordController method handleAnswerSecurityQuestionPost.
@RequestMapping(value = "/answer-sec-qn", method = RequestMethod.POST)
public ModelAndView handleAnswerSecurityQuestionPost(@RequestParam("secQnAnswer") final String secQnAnswer, @RequestParam("stateToken") final String stateToken) {
final ModelAndView modelAndView = new ModelAndView("change-password");
final AuthenticationResponse authenticationResponse;
try {
authenticationResponse = authenticationClient.answerRecoveryQuestion(secQnAnswer, stateToken, ignoringStateHandler);
} catch (final AuthenticationException e) {
logger.error("Answer Sec Qn Error - Status: {}, Code: {}, Message: {}", e.getStatus(), e.getCode(), e.getMessage());
final ModelAndView errorView = new ModelAndView("change-password");
errorView.addObject("error", e.getStatus() + ":" + e.getCode() + ":" + e.getMessage());
return errorView;
}
logger.info("Answer Recovery Qn Status: {}", authenticationResponse.getStatus());
modelAndView.addObject("stateToken", stateToken);
return modelAndView;
}
Aggregations