Search in sources :

Example 1 with TokenCreateResponse

use of io.getlime.security.powerauth.rest.api.model.response.v2.TokenCreateResponse in project powerauth-restful-integration by lime-company.

the class TokenService method createToken.

/**
 * Create token.
 * @param request Create token request.
 * @param authentication PowerAuth API authentication.
 * @return Create token response.
 * @throws PowerAuthAuthenticationException In case token could not be created.
 */
public TokenCreateResponse createToken(TokenCreateRequest request, PowerAuthApiAuthentication authentication) throws PowerAuthAuthenticationException {
    try {
        // Fetch activation ID and signature type
        final String activationId = authentication.getActivationContext().getActivationId();
        final PowerAuthSignatureTypes signatureFactors = authentication.getAuthenticationContext().getSignatureType();
        // Fetch data from the request
        final String ephemeralPublicKey = request.getEphemeralPublicKey();
        // Prepare a signature type converter
        SignatureTypeConverter converter = new SignatureTypeConverter();
        // Create a token
        final CreateTokenResponse token = powerAuthClient.v2().createToken(activationId, ephemeralPublicKey, converter.convertFrom(signatureFactors));
        // Prepare a response
        final TokenCreateResponse response = new TokenCreateResponse();
        response.setMac(token.getMac());
        response.setEncryptedData(token.getEncryptedData());
        return response;
    } catch (Exception ex) {
        logger.warn("Creating PowerAuth token failed, error: {}", ex.getMessage());
        logger.debug(ex.getMessage(), ex);
        throw new PowerAuthTokenErrorException();
    }
}
Also used : PowerAuthTokenErrorException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthTokenErrorException) CreateTokenResponse(com.wultra.security.powerauth.client.v2.CreateTokenResponse) PowerAuthSignatureTypes(io.getlime.security.powerauth.crypto.lib.enums.PowerAuthSignatureTypes) TokenCreateResponse(io.getlime.security.powerauth.rest.api.model.response.v2.TokenCreateResponse) PowerAuthTokenErrorException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthTokenErrorException) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthAuthenticationException) SignatureTypeConverter(io.getlime.security.powerauth.rest.api.spring.converter.v2.SignatureTypeConverter)

Aggregations

CreateTokenResponse (com.wultra.security.powerauth.client.v2.CreateTokenResponse)1 PowerAuthSignatureTypes (io.getlime.security.powerauth.crypto.lib.enums.PowerAuthSignatureTypes)1 TokenCreateResponse (io.getlime.security.powerauth.rest.api.model.response.v2.TokenCreateResponse)1 SignatureTypeConverter (io.getlime.security.powerauth.rest.api.spring.converter.v2.SignatureTypeConverter)1 PowerAuthAuthenticationException (io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthAuthenticationException)1 PowerAuthTokenErrorException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthTokenErrorException)1