use of net.petafuel.styx.core.xs2a.oauth.http.RefreshTokenRequest in project styx by petafuel.
the class PreAuthAccessFilter method refreshToken.
private OAuthSession refreshToken(OAuthSession oAuthSession) throws OAuthTokenExpiredException {
String state = oAuthSession.getState();
RefreshTokenRequest request = new RefreshTokenRequest(oAuthSession.getRefreshToken());
OAuthService service = new OAuthService();
try {
oAuthSession = service.tokenRequest(oAuthSession.getTokenEndpoint(), request);
oAuthSession.setState(state);
PersistentOAuthSession.update(oAuthSession);
return oAuthSession;
} catch (BankRequestFailedException expiredToken) {
throw new OAuthTokenExpiredException(OAuthTokenExpiredException.MESSAGE);
}
}
use of net.petafuel.styx.core.xs2a.oauth.http.RefreshTokenRequest in project styx by petafuel.
the class RefreshTokenTest method refreshTokenTest.
@Tag("integration")
@Test
public void refreshTokenTest() throws BankRequestFailedException {
String preAuthId = "cfa0cfd3-d4db-47c6-ad45-addececcfb02";
OAuthSession session = PersistentOAuthSession.getById(UUID.fromString(preAuthId));
if (session.getAccessTokenExpiresAt().before(new Date()) && session.getRefreshTokenExpiresAt().after(new Date())) {
System.out.println("Token has expired");
RefreshTokenRequest request = new RefreshTokenRequest(session.getRefreshToken());
OAuthService service = new OAuthService();
OAuthSession refreshed = service.tokenRequest(session.getTokenEndpoint(), request);
refreshed.setState(session.getState());
PersistentOAuthSession.update(refreshed);
Assert.assertNotEquals(session.getAccessToken(), refreshed.getAccessToken());
System.out.println("Token is refreshed");
}
}
use of net.petafuel.styx.core.xs2a.oauth.http.RefreshTokenRequest in project styx by petafuel.
the class OAuthService method refreshToken.
public static OAuthSession refreshToken(OAuthSession oAuthSession) throws OAuthTokenExpiredException {
String state = oAuthSession.getState();
RefreshTokenRequest request = new RefreshTokenRequest(oAuthSession.getRefreshToken());
OAuthService service = new OAuthService();
try {
oAuthSession = service.tokenRequest(oAuthSession.getTokenEndpoint(), request);
oAuthSession.setState(state);
PersistentOAuthSession.update(oAuthSession);
return oAuthSession;
} catch (BankRequestFailedException expiredToken) {
throw new OAuthTokenExpiredException(OAuthTokenExpiredException.MESSAGE);
}
}
Aggregations