use of io.vertx.reactivex.ext.web.Session in project api-framework by vinscom.
the class LoadUserFromSessionRouteBuillder method handle.
public void handle(RoutingContext pRoutingContext) {
Session session = pRoutingContext.session();
if (session != null && getOAuth2Auth() != null) {
JsonObject principal = session.get(FrameworkConstants.Session.PRINCIPAL);
if (principal != null) {
OAuth2AuthProviderImpl provider = (OAuth2AuthProviderImpl) getOAuth2Auth().getDelegate();
try {
OAuth2TokenImpl token = new OAuth2TokenImpl(provider, principal);
pRoutingContext.setUser(new AccessToken(token));
} catch (RuntimeException e) {
getLog().error(e);
pRoutingContext.fail(401);
return;
}
}
}
pRoutingContext.next();
}
use of io.vertx.reactivex.ext.web.Session in project api-framework by vinscom.
the class OIDCCallbackRouteBuilder method handle.
public void handle(RoutingContext pRoutingCoutext) {
JsonObject tokenConfig = getTokenConfig(pRoutingCoutext);
getOAuth2Auth().getDelegate().authenticate(tokenConfig, (response) -> {
if (response.succeeded()) {
Session session = pRoutingCoutext.session().regenerateId();
session.put(FrameworkConstants.Session.PRINCIPAL, response.result().principal());
getLog().debug(() -> "Success URL:" + getSuccessURL(pRoutingCoutext));
pRoutingCoutext.response().putHeader(HttpHeaders.LOCATION, getSuccessURL(pRoutingCoutext)).setStatusCode(302).end();
} else {
getLog().error(response.cause());
getLog().debug(() -> "Fail URL:" + getFailURL(pRoutingCoutext));
pRoutingCoutext.response().putHeader(HttpHeaders.LOCATION, getFailURL(pRoutingCoutext)).setStatusCode(302).end();
}
});
}
Aggregations