.setClientID("client-id") .setClientSecret("client-secret") .setSite("http://localhost:10000"));
.setClientID("client-id") .setClientSecret("client-secret") .setSite("http://localhost:10000"));
@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"); }
.setClientID("client-id") .setClientSecret("client-secret") .setSite("http://localhost:10000"));
vertx, new OAuth2ClientOptions() .setClientID("dummy-client") .addPubSecKey(new PubSecKeyOptions() .setAlgorithm("RS256")
/** * 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 SoundCloud * * @param clientId the client id given to you by SoundCloud * @param clientSecret the client secret given to you by SoundCloud * @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://api.soundcloud.com") .setTokenPath("/oauth2/token") .setAuthorizationPath("/connect") .setUserInfoPath("/me.json") .setClientID(clientId) .setClientSecret(clientSecret)); } }
/** * Create a OAuth2Auth provider for live.com * * @param clientId the client id given to you by live.com * @param clientSecret the client secret given to you by live.com * @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://login.live.com") .setTokenPath("/oauth20_token.srf") .setAuthorizationPath("/oauth20_authorize.srf") .setScopeSeparator(" ") .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)); } }
/** * Create a OAuth2Auth provider for Mailchimp * * @param clientId the client id given to you by Mailchimp * @param clientSecret the client secret given to you by Mailchimp * @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://login.mailchimp.com") .setTokenPath("/oauth2/token") .setAuthorizationPath("/oauth2/authorize") .setUserInfoPath("/oauth2/metadata") .setClientID(clientId) .setClientSecret(clientSecret)); } }
/** * Create a OAuth2Auth provider for Twitter * * @param clientId the client id given to you by Twitter * @param clientSecret the client secret given to you by Twitter * @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://api.twitter.com") .setTokenPath("/oauth/access_token") .setAuthorizationPath("/oauth/authorize") .setUserInfoPath("/1.1/users/show.json") .setClientID(clientId) .setClientSecret(clientSecret)); } }
/** * Create a OAuth2Auth provider for CloudFoundry UAA * * @param clientId the client id given to you by CloudFoundry UAA * @param clientSecret the client secret given to you by CloudFoundry UAA * @param uuaURL the url to your UUA server instance * @param httpClientOptions custom http client options */ static OAuth2Auth create(Vertx vertx, String clientId, String clientSecret, String uuaURL, HttpClientOptions httpClientOptions) { return OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions(httpClientOptions) .setSite(uuaURL) .setTokenPath("/oauth/token") .setAuthorizationPath("/oauth/authorize") .setScopeSeparator(" ") .setClientID(clientId) .setClientSecret(clientSecret)); } }
/** * Create a OAuth2Auth provider for Salesforce * * @param clientId the client id given to you by Salesforce * @param clientSecret the client secret given to you by Salesforce * @param httpClientOptions custom http client options */ static OAuth2Auth create(Vertx vertx, String clientId, String clientSecret, HttpClientOptions httpClientOptions) { return OAuth2Auth.create(vertx, new OAuth2ClientOptions(httpClientOptions) .setFlow(OAuth2FlowType.AUTH_CODE) .setSite("http://login.salesforce.com") .setTokenPath("/services/oauth2/token") .setAuthorizationPath("/services/oauth2/authorize") .setScopeSeparator("+") .setClientID(clientId) .setClientSecret(clientSecret)); }
/** * Create a OAuth2Auth provider for Stripe * * @param clientId the client id given to you by Stripe * @param clientSecret the client secret given to you by Stripe * @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://connect.stripe.com") .setTokenPath("/oauth2/token") .setAuthorizationPath("/oauth2/authorize") .setUserInfoPath("/v1/account") .setScopeSeparator(" ") .setClientID(clientId) .setClientSecret(clientSecret)); } }
/** * Create a OAuth2Auth provider for App.net * * @param clientId the client id given to you by box.com * @param clientSecret the client secret given to you by box.com * @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://account.box.com") .setTokenPath("/api/oauth2/token") .setAuthorizationPath("/api/oauth2/authorize") .setUserInfoPath("/users/me") .setScopeSeparator(" ") .setClientID(clientId) .setClientSecret(clientSecret)); } }
/** * Create a OAuth2Auth provider for Facebook * * @param clientId the client id given to you by Facebook * @param clientSecret the client secret given to you by Facebook * @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://www.facebook.com") .setTokenPath("https://graph.facebook.com/oauth/access_token") .setAuthorizationPath("/dialog/oauth") .setUserInfoPath("https://graph.facebook.com/me") .setScopeSeparator(",") .setClientID(clientId) .setClientSecret(clientSecret)); } }
/** * Create a OAuth2Auth provider for LinkedIn * * @param clientId the client id given to you by LinkedIn * @param clientSecret the client secret given to you by LinkedIn * @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://www.linkedin.com") .setTokenPath("/uas/oauth2/accessToken") .setAuthorizationPath("/uas/oauth2/authorization") .setUserInfoPath("/people/~") .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(); } }
@Before public void setUp(TestContext should) { final Async test = should.async(); OAuth2ClientOptions options = new OAuth2ClientOptions() .setFlow(OAuth2FlowType.PASSWORD) .setSite(site + "/auth/realms/vertx-test") .setClientID("public-client"); options.setTrustAll(true); KeycloakAuth.discover( rule.vertx(), options, discover -> { should.assertTrue(discover.succeeded()); keycloak = discover.result(); test.complete(); }); }
@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"); }