OAuth2Auth oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.PASSWORD, new OAuth2ClientOptions() .setClientID("client-id") .setClientSecret("client-secret")
OAuth2Auth oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions() .setClientID("client-id") .setClientSecret("client-secret")
/** * Create a OAuth2 auth provider * * @param vertx the Vertx instance * @return the auth provider */ static OAuth2Auth create(Vertx vertx) { return create(vertx, new OAuth2ClientOptions()); }
@Test public void testBearerOnly() throws Exception { // lets mock a oauth2 server using code auth code flow OAuth2Auth oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions().setClientID("client-id")); OAuth2AuthHandler oauth2Handler = OAuth2AuthHandler.create(oauth2); // protect everything under /protected router.route("/protected/*").handler(oauth2Handler); // mount some handler under the protected zone router.route("/protected/somepage").handler(rc -> { assertNotNull(rc.user()); rc.response().end("Welcome to the protected resource!"); }); testRequest(HttpMethod.GET, "/protected/somepage", 401, "Unauthorized"); // Now try again with fake credentials testRequest(HttpMethod.GET, "/protected/somepage", req -> req.putHeader("Authorization", "Bearer 4adc339e0"), 401, "Unauthorized", "Unauthorized"); }
OAuth2Auth oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions() .setClientID("client-id") .setClientSecret("client-secret")
/** * Create a OAuth2 auth provider * @param vertx the Vertx instance * @param flow * @return the auth provider */ @Deprecated() public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, OAuth2FlowType flow) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.OAuth2Auth.create(vertx.getDelegate(), flow)); return ret; }
/** * Create a OAuth2 auth provider * @param vertx the Vertx instance * @param flow * @param config the config * @return the auth provider */ @Deprecated() public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, OAuth2FlowType flow, OAuth2ClientOptions config) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.OAuth2Auth.create(vertx.getDelegate(), flow, config)); return ret; }
/** * Create a OAuth2 auth provider * @param vertx the Vertx instance * @param flow * @return the auth provider */ @Deprecated() public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, OAuth2FlowType flow) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.OAuth2Auth.create(vertx.getDelegate(), flow)); return ret; }
/** * Create a OAuth2 auth provider * @param vertx the Vertx instance * @param flow * @param config the config * @return the auth provider */ @Deprecated() public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, OAuth2FlowType flow, OAuth2ClientOptions config) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.OAuth2Auth.create(vertx.getDelegate(), flow, config)); return ret; }
/** * Create a OAuth2 auth provider * @param vertx the Vertx instance * @param config the config * @return the auth provider */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, OAuth2ClientOptions config) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.OAuth2Auth.create(vertx.getDelegate(), config)); return ret; }
/** * Create a OAuth2 auth provider * @param vertx the Vertx instance * @return the auth provider */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.OAuth2Auth.create(vertx.getDelegate())); return ret; }
/** * Create a OAuth2 auth provider * @param vertx the Vertx instance * @return the auth provider */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.OAuth2Auth.create(vertx.getDelegate())); return ret; }
/** * Create a OAuth2 auth provider * @param vertx the Vertx instance * @param config the config * @return the auth provider */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, OAuth2ClientOptions config) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance(io.vertx.ext.auth.oauth2.OAuth2Auth.create(vertx.getDelegate(), config)); return ret; }
public static io.vertx.ext.auth.oauth2.OAuth2Auth create(io.vertx.ext.auth.oauth2.OAuth2Auth j_receiver, io.vertx.core.Vertx vertx, io.vertx.ext.auth.oauth2.OAuth2FlowType flow, java.util.Map<String, Object> config) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.auth.oauth2.OAuth2Auth.create(vertx, flow, config != null ? new io.vertx.ext.auth.oauth2.OAuth2ClientOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(config)) : null)); } public static io.vertx.ext.auth.oauth2.OAuth2Auth create(io.vertx.ext.auth.oauth2.OAuth2Auth j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> config) {
public static io.vertx.ext.auth.oauth2.OAuth2Auth create(io.vertx.ext.auth.oauth2.OAuth2Auth j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> config) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.auth.oauth2.OAuth2Auth.create(vertx, config != null ? new io.vertx.ext.auth.oauth2.OAuth2ClientOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(config)) : null)); } }
.create( vertx, new OAuth2ClientOptions()
/** * Create a OAuth2Auth provider for Foursquare * * @param clientId the client id given to you by Foursquare * @param clientSecret the client secret given to you by Foursquare * @param httpClientOptions custom http client options */ static OAuth2Auth create(Vertx vertx, String clientId, String clientSecret, HttpClientOptions httpClientOptions) { return OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions(httpClientOptions) .setSite("https://foursquare.com") .setTokenPath("/oauth2/access_token") .setAuthorizationPath("/oauth2/authenticate") .setUserInfoPath("/users/self") .setClientID(clientId) .setClientSecret(clientSecret)); } }
/** * Create a OAuth2Auth provider for Heroku * * @param clientId the client id given to you by Heroku * @param clientSecret the client secret given to you by Heroku * @param httpClientOptions custom http client options */ static OAuth2Auth create(Vertx vertx, String clientId, String clientSecret, HttpClientOptions httpClientOptions) { return OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions(httpClientOptions) .setSite("https://id.heroku.com") .setTokenPath("/oauth/token") .setAuthorizationPath("/oauth/authorize") .setScopeSeparator(" ") .setClientID(clientId) .setClientSecret(clientSecret)); } }
@Test public void unknownHost() { OAuth2Auth auth = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions() .setClientID("client-id") .setClientSecret("client-secret") .setSite("http://zlouklfoux.net.com.info.pimpo.molo")); auth.authenticate(tokenConfig, res -> { if (res.failed()) { assertThat(res.cause(), instanceOf(UnknownHostException.class)); testComplete(); } else { fail("Should have failed"); } }); await(); } }
@Test public void testBearerOnly() throws Exception { // lets mock a oauth2 server using code auth code flow OAuth2Auth oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions().setClientID("client-id")); OAuth2AuthHandler oauth2Handler = OAuth2AuthHandler.create(oauth2); // protect everything under /protected router.route("/protected/*").handler(oauth2Handler); // mount some handler under the protected zone router.route("/protected/somepage").handler(rc -> { assertNotNull(rc.user()); rc.response().end("Welcome to the protected resource!"); }); testRequest(HttpMethod.GET, "/protected/somepage", 401, "Unauthorized"); // Now try again with fake credentials testRequest(HttpMethod.GET, "/protected/somepage", req -> req.putHeader("Authorization", "Bearer 4adc339e0"), 401, "Unauthorized", "Unauthorized"); }