com.clouway.oauth2.IssueNewTokenActivity Maven / Gradle / Ivy
package com.clouway.oauth2;
import com.clouway.oauth2.authorization.Authorization;
import com.clouway.oauth2.authorization.ClientAuthorizationRepository;
import com.clouway.oauth2.client.Client;
import com.clouway.oauth2.http.Request;
import com.clouway.oauth2.http.Response;
import com.clouway.oauth2.token.Token;
import com.clouway.oauth2.token.Tokens;
import com.google.common.base.Optional;
import java.util.Date;
/**
* IssueNewTokenActivity is representing the activity which is performed for issuing of new token.
*
* @author Miroslav Genov ([email protected])
*/
public class IssueNewTokenActivity implements ClientActivity {
private final Tokens tokens;
private final ClientAuthorizationRepository clientAuthorizationRepository;
public IssueNewTokenActivity(Tokens tokens,
ClientAuthorizationRepository clientAuthorizationRepository) {
this.tokens = tokens;
this.clientAuthorizationRepository = clientAuthorizationRepository;
}
@Override
public Response execute(Client client, Request request, Date instant) {
String authCode = request.param("code");
Optional opt = clientAuthorizationRepository.findAuthorization(client, authCode);
if (!opt.isPresent()) {
return OAuthError.invalidGrant();
}
Authorization authorization = opt.get();
Token newToken = tokens.issueToken(authorization.identityId, instant);
return new BearerTokenResponse(newToken.value, newToken.expiresInSeconds, newToken.refreshToken);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy