Search in sources :

Example 1 with ActionTokenRequestDTO

use of com.nexblocks.authguard.api.dto.requests.ActionTokenRequestDTO in project AuthGuard by AuthGuard.

the class ActionTokensRoute method createToken.

@Override
public void createToken(final Context context) {
    final ActionTokenRequestDTO request = actionTokenRequestBodyHandler.getValidated(context);
    final Try<ActionTokenBO> result;
    if (request.getType() == ActionTokenRequestType.OTP) {
        result = actionTokenService.generateFromOtp(request.getOtp().getPasswordId(), request.getOtp().getPassword(), request.getAction());
    } else {
        final AuthRequestBO authRequest = restMapper.toBO(request.getBasic());
        result = actionTokenService.generateFromBasicAuth(authRequest, request.getAction());
    }
    if (result.isFailure()) {
        throw (ServiceException) result.getCause();
    }
    context.status(201).json(restMapper.toDTO(result.get()));
}
Also used : ServiceException(com.nexblocks.authguard.service.exceptions.ServiceException) ActionTokenRequestDTO(com.nexblocks.authguard.api.dto.requests.ActionTokenRequestDTO) ActionTokenBO(com.nexblocks.authguard.service.model.ActionTokenBO) AuthRequestBO(com.nexblocks.authguard.service.model.AuthRequestBO)

Aggregations

ActionTokenRequestDTO (com.nexblocks.authguard.api.dto.requests.ActionTokenRequestDTO)1 ServiceException (com.nexblocks.authguard.service.exceptions.ServiceException)1 ActionTokenBO (com.nexblocks.authguard.service.model.ActionTokenBO)1 AuthRequestBO (com.nexblocks.authguard.service.model.AuthRequestBO)1