use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.
the class AuthorizationCodeTokenHandler method responseToken.
private void responseToken() throws OAuthSystemException {
AccessToken accessToken = oauthService.retrieveAuthorizationCodeAccessToken(clientDetails(), tokenRequest.getCode());
final OAuthResponse tokenResponse = createTokenResponse(accessToken, false);
LOG.debug("'authorization_code' response: {}", tokenResponse);
WebUtils.writeOAuthJsonResponse(response, tokenResponse);
}
use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.
the class RefreshTokenHandler method handleAfterValidation.
@Override
public void handleAfterValidation() throws OAuthProblemException, OAuthSystemException {
final String refreshToken = tokenRequest.getRefreshToken();
AccessToken accessToken = oauthService.changeAccessTokenByRefreshToken(refreshToken, tokenRequest.getClientId());
final OAuthResponse tokenResponse = createTokenResponse(accessToken, false);
LOG.debug("'refresh_token' response: {}", tokenResponse);
WebUtils.writeOAuthJsonResponse(response, tokenResponse);
}
use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.
the class RefreshTokenClientDetailsValidator 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 refreshToken = tokenRequest.getRefreshToken();
AccessToken accessToken = oauthService.loadAccessTokenByRefreshToken(refreshToken, oauthRequest.getClientId());
if (accessToken == null || accessToken.refreshTokenExpired()) {
LOG.debug("Invalid refresh_token: '{}'", refreshToken);
return invalidRefreshTokenResponse(refreshToken);
}
return null;
}
use of io.github.tesla.authz.domain.AccessToken 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;
}
use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.
the class OauthService method retrieveAccessToken.
public AccessToken retrieveAccessToken(ClientDetails clientDetails, Set<String> scopes, boolean includeRefreshToken) throws OAuthSystemException {
String scope = OAuthUtils.encodeScopes(scopes);
final String username = currentUsername();
final String clientId = clientDetails.getClientId();
final String authenticationId = authenticationIdGenerator.generate(clientId, username, scope);
AccessToken accessToken = oauthRepository.findAccessToken(clientId, username, authenticationId);
if (accessToken == null) {
accessToken = createAndSaveAccessToken(clientDetails, includeRefreshToken, username, authenticationId);
LOG.debug("Create a new AccessToken: {}", accessToken);
}
return accessToken;
}
Aggregations