Search in sources :

Example 1 with OauthCode

use of io.github.tesla.authz.domain.OauthCode in project tesla by linking12.

the class OauthService method retrieveAuthCode.

public String retrieveAuthCode(ClientDetails clientDetails) throws OAuthSystemException {
    final String clientId = clientDetails.getClientId();
    final String username = currentUsername();
    OauthCode oauthCode = oauthRepository.findOauthCodeByUsernameClientId(username, clientId);
    if (oauthCode != null) {
        LOG.debug("OauthCode ({}) is existed, remove it and create a new one", oauthCode);
        oauthRepository.deleteOauthCode(oauthCode);
    }
    oauthCode = createOauthCode(clientDetails);
    return oauthCode.code();
}
Also used : OauthCode(io.github.tesla.authz.domain.OauthCode)

Example 2 with OauthCode

use of io.github.tesla.authz.domain.OauthCode in project tesla by linking12.

the class OauthService method retrieveAuthorizationCodeAccessToken.

public AccessToken retrieveAuthorizationCodeAccessToken(ClientDetails clientDetails, String code) throws OAuthSystemException {
    final OauthCode oauthCode = loadOauthCode(code, clientDetails);
    final String username = oauthCode.username();
    final String clientId = clientDetails.getClientId();
    final String authenticationId = authenticationIdGenerator.generate(clientId, username, null);
    AccessToken accessToken = oauthRepository.findAccessToken(clientId, username, authenticationId);
    if (accessToken != null) {
        LOG.debug("Delete existed AccessToken: {}", accessToken);
        oauthRepository.deleteAccessToken(accessToken);
    }
    accessToken = createAndSaveAccessToken(clientDetails, clientDetails.supportRefreshToken(), username, authenticationId);
    LOG.debug("Create a new AccessToken: {}", accessToken);
    return accessToken;
}
Also used : OauthCode(io.github.tesla.authz.domain.OauthCode) AccessToken(io.github.tesla.authz.domain.AccessToken)

Example 3 with OauthCode

use of io.github.tesla.authz.domain.OauthCode in project tesla by linking12.

the class OauthService method saveAuthorizationCode.

public OauthCode saveAuthorizationCode(String authCode, ClientDetails clientDetails) {
    final String username = currentUsername();
    OauthCode oauthCode = new OauthCode().code(authCode).username(username).clientId(clientDetails.getClientId());
    oauthRepository.saveOauthCode(oauthCode);
    LOG.debug("Save OauthCode: {}", oauthCode);
    return oauthCode;
}
Also used : OauthCode(io.github.tesla.authz.domain.OauthCode)

Example 4 with OauthCode

use of io.github.tesla.authz.domain.OauthCode in project tesla by linking12.

the class AuthorizationCodeClientDetailsValidator method validateSelf.

@Override
protected OAuthResponse validateSelf(ClientDetails clientDetails) throws OAuthSystemException {
    final String grantType = grantType();
    if (!clientDetails.grantTypes().contains(grantType)) {
        LOG.debug("Invalid grant_type '{}', client_id = '{}'", grantType, clientDetails.getClientId());
        return invalidGrantTypeResponse(grantType);
    }
    final String clientSecret = oauthRequest.getClientSecret();
    if (clientSecret == null || !clientSecret.equals(clientDetails.getClientSecret())) {
        LOG.debug("Invalid client_secret '{}', client_id = '{}'", clientSecret, clientDetails.getClientId());
        return invalidClientSecretResponse();
    }
    final String redirectURI = oauthRequest.getRedirectURI();
    if (redirectURI == null || !redirectURI.equals(clientDetails.getRedirectUri())) {
        LOG.debug("Invalid redirect_uri '{}', client_id = '{}'", redirectURI, clientDetails.getClientId());
        return invalidRedirectUriResponse();
    }
    String code = getCode();
    OauthCode oauthCode = oauthService.loadOauthCode(code, clientDetails());
    if (oauthCode == null) {
        LOG.debug("Invalid code '{}', client_id = '{}'", code, clientDetails.getClientId());
        return invalidCodeResponse(code);
    }
    return null;
}
Also used : OauthCode(io.github.tesla.authz.domain.OauthCode)

Example 5 with OauthCode

use of io.github.tesla.authz.domain.OauthCode in project tesla by linking12.

the class OauthService method removeOauthCode.

public boolean removeOauthCode(String code, ClientDetails clientDetails) {
    final OauthCode oauthCode = loadOauthCode(code, clientDetails);
    final int rows = oauthRepository.deleteOauthCode(oauthCode);
    return rows > 0;
}
Also used : OauthCode(io.github.tesla.authz.domain.OauthCode)

Aggregations

OauthCode (io.github.tesla.authz.domain.OauthCode)6 AccessToken (io.github.tesla.authz.domain.AccessToken)1