use of ru.ratauth.entities.Token in project ratauth by alfa-laboratory.
the class OpenIdAuthorizeService method buildResponse.
@SneakyThrows
private static AuthzResponse buildResponse(RelyingParty relyingParty, Session session, VerifyResult verifyResult, TokenCache tokenCache, AuthzRequest authzRequest) {
String redirectUri = authzRequest.getRedirectURI();
final String targetRedirectURI = createRedirectURI(relyingParty, redirectUri);
// in case of autCode sent by authProvider
if (session == null || CollectionUtils.isEmpty(session.getEntries())) {
AuthzResponse resp = AuthzResponse.builder().location(relyingParty.getAuthorizationRedirectURI()).data(verifyResult.getData()).redirectURI(targetRedirectURI).build();
return resp;
}
AuthEntry entry = session.getEntry(relyingParty.getName()).get();
AuthzResponse resp = AuthzResponse.builder().location(entry.getRedirectUrl()).sessionToken(session.getSessionToken()).acrValues(verifyResult.getAcrValues()).data(verifyResult.getData()).build();
final Optional<Token> tokenOptional = entry.getLatestToken();
// implicit auth
if (tokenOptional.isPresent()) {
final Token token = tokenOptional.get();
resp.setToken(token.getToken());
if (tokenCache != null)
resp.setIdToken(tokenCache.getIdToken());
resp.setTokenType(TokenType.BEARER);
resp.setRefreshToken(token.getRefreshToken());
resp.setExpiresIn(token.getExpiresIn().getTime());
} else {
generateAuthCode(relyingParty, session, authzRequest, targetRedirectURI, entry, resp);
}
return resp;
}
Aggregations