@Override public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) { Session session = context.session(); if (session != null) { // Now redirect to the login url - we'll get redirected back here after successful login session.put(returnURLParam, context.request().uri()); handler.handle(Future.failedFuture(new HttpStatusException(302, loginRedirectURL))); } else { handler.handle(Future.failedFuture("No session - did you forget to include a SessionHandler?")); } } }
log.warn("The callback route is shaded by the OAuth2AuthHandler, ensure the callback route is added BEFORE the OAuth2AuthHandler route!"); handler.handle(Future.failedFuture(new HttpStatusException(500, "Infinite redirect loop [oauth2 callback]"))); } else { handler.handle(Future.failedFuture(new HttpStatusException(302, authURI(context.request().uri())))); handler.handle(Future.failedFuture(new HttpStatusException(401, decodeToken.cause().getMessage()))); return;
processException(ctx, new HttpStatusException(401, authN.cause()));
@Override public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) { Session session = context.session(); if (session != null) { // Now redirect to the login url - we'll get redirected back here after successful login session.put(returnURLParam, context.request().uri()); handler.handle(Future.failedFuture(new HttpStatusException(302, loginRedirectURL))); } else { handler.handle(Future.failedFuture("No session - did you forget to include a SessionHandler?")); } } }
@Override public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) { parseAuthorization(context, true, parseAuthorization -> { if (parseAuthorization.failed()) { handler.handle(Future.failedFuture(parseAuthorization.cause())); return; } // Authorization header could be null as we mark it as optional final String token = parseAuthorization.result(); if (token == null) { context.next(); } else { // attempt to decode the token and handle it as a user ((OAuth2Auth) authProvider).decodeToken(token, decodeToken -> { if (decodeToken.failed()) { handler.handle(Future.failedFuture(new HttpStatusException(401, decodeToken.cause().getMessage()))); return; } context.setUser(decodeToken.result()); // continue handler.handle(Future.succeededFuture()); }); } }); }
log.warn("The callback route is shaded by the OAuth2AuthHandler, ensure the callback route is added BEFORE the OAuth2AuthHandler route!"); handler.handle(Future.failedFuture(new HttpStatusException(500, "Infinite redirect loop [oauth2 callback]"))); } else { handler.handle(Future.failedFuture(new HttpStatusException(302, authURI(context.request().uri())))); handler.handle(Future.failedFuture(new HttpStatusException(401, decodeToken.cause().getMessage()))); return;
@Override public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) { Session session = context.session(); if (session != null) { try { // Save current request in session - we'll get redirected back here after successful login HttpServerRequest request = context.request(); session.put(returnURLParam, UriBuilderRequest.resolveProxyRequest( new io.vertx.reactivex.core.http.HttpServerRequest(request), request.path(), request.params().entries().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))); // Now redirect to the login url String uri = UriBuilderRequest.resolveProxyRequest( new io.vertx.reactivex.core.http.HttpServerRequest(request), loginRedirectURL, Collections.singletonMap(OAuth2Constants.CLIENT_ID, request.getParam(OAuth2Constants.CLIENT_ID))); handler.handle(Future.failedFuture(new HttpStatusException(302, uri))); } catch (Exception e) { logger.warn("Failed to decode login redirect url", e); handler.handle(Future.failedFuture(new HttpStatusException(302, loginRedirectURL))); } } else { handler.handle(Future.failedFuture("No session - did you forget to include a SessionHandler?")); } } }
@Override public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) { Session session = context.session(); if (session != null) { try { // Save current request in session - we'll get redirected back here after successful login HttpServerRequest request = context.request(); session.put(returnURLParam, UriBuilderRequest.resolveProxyRequest( new io.vertx.reactivex.core.http.HttpServerRequest(request), request.path(), request.params().entries().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))); // Now redirect to the login url String uri = UriBuilderRequest.resolveProxyRequest( new io.vertx.reactivex.core.http.HttpServerRequest(request), loginRedirectURL, Collections.singletonMap(OAuth2Constants.CLIENT_ID, request.getParam(OAuth2Constants.CLIENT_ID))); handler.handle(Future.failedFuture(new HttpStatusException(302, uri))); } catch (Exception e) { logger.warn("Failed to decode login redirect url", e); handler.handle(Future.failedFuture(new HttpStatusException(302, loginRedirectURL))); } } else { handler.handle(Future.failedFuture("No session - did you forget to include a SessionHandler?")); } } }
processException(ctx, new HttpStatusException(401, authN.cause()));