@Test public void shouldAuthenticate() { Authentication authentication = mock(Authentication.class); AuthenticationContext authenticationContext = mock(AuthenticationContext.class); when(authentication.getContext()).thenReturn(authenticationContext); io.gravitee.gateway.api.Request request = mock(io.gravitee.gateway.api.Request.class); when(authenticationContext.request()).thenReturn(request); MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>(); parameters.set("code", "facebookAuthorizationCode"); when(request.parameters()).thenReturn(parameters); when(configuration.getCodeParameter()).thenReturn("code"); when(configuration.getClientId()).thenReturn("testClientId"); when(configuration.getClientSecret()).thenReturn("testClientSecret"); when(configuration.getAccessTokenUri()).thenReturn("https: when(configuration.getUserProfileUri()).thenReturn("https: when(authentication.getContext().get("redirect_uri")).thenReturn("https: when(httpResponse.statusCode()) .thenReturn(HttpStatusCode.OK_200) .thenReturn(HttpStatusCode.OK_200); when(httpResponse.bodyAsJsonObject()) .thenReturn(new JsonObject().put("access_token", "facebookGeneratedAccessToken")) .thenReturn(new JsonObject().put(FacebookUser.ID, "facebookID") .put(FacebookUser.EMAIL, "email@facebook.com") .put(FacebookUser.NAME, "facebookName") .put(FacebookUser.LOCATION, new JsonObject().put("location", new JsonObject() .put(LOCATION_STREET_FIELD, "facebookStreet") .put(LOCATION_CITY_FIELD, "facebookCity") .put(LOCATION_REGION_FIELD, "facebookRegion") .put(LOCATION_ZIP_FIELD, 123456) .put(LOCATION_COUNTRY_FIELD, "facebookCountry"))) .put(FacebookUser.BIRTHDAY, "10/24") .put(FacebookUser.ABOUT, "facebook about me")); TestObserver<User> obs = cut.loadUserByUsername(authentication).test(); obs.awaitTerminalEvent(); obs.assertValue(user -> { assertEquals("facebookID", user.getId()); assertEquals("facebookID", user.getId()); assertEquals("facebookID", user.getAdditionalInformation().get(StandardClaims.SUB)); assertEquals("facebookName", user.getAdditionalInformation().get(StandardClaims.NAME)); assertEquals("facebookID", user.getAdditionalInformation().get(StandardClaims.PREFERRED_USERNAME)); HashMap<String, Object> address = (HashMap<String, Object>) user.getAdditionalInformation().get(StandardClaims.ADDRESS); assertNotNull(address); assertEquals("facebookStreet", address.get("street_address")); assertEquals("facebookCity", address.get("locality")); assertEquals("facebookRegion", address.get("region")); assertEquals(123456, address.get("postal_code")); assertEquals("facebookCountry", address.get("country")); assertEquals("0000-10-24", user.getAdditionalInformation().get(StandardClaims.BIRTHDATE)); assertNotNull(user.getAdditionalInformation().get(FacebookUser.ABOUT)); return true; }); verify(client, times(1)).postAbs("https: verify(client, times(1)).postAbs("https: }
@Override public Maybe<User> loadUserByUsername(Authentication authentication) { return authenticate(authentication) .flatMap(token -> this.profile(token, authentication)); }
FacebookAuthenticationProvider extends AbstractSocialAuthenticationProvider<FacebookIdentityProviderConfiguration> { @Override public Maybe<User> loadUserByUsername(Authentication authentication) { return authenticate(authentication) .flatMap(token -> this.profile(token, authentication)); } }
FacebookAuthenticationProvider extends AbstractSocialAuthenticationProvider<FacebookIdentityProviderConfiguration> { @Override public Maybe<User> loadUserByUsername(Authentication authentication) { return authenticate(authentication) .flatMap(token -> this.profile(token, authentication)); }  }
FacebookAuthenticationProvider extends AbstractSocialAuthenticationProvider<FacebookIdentityProviderConfiguration> { @Override public Maybe<User> loadUserByUsername(Authentication authentication) { return authenticate(authentication) .flatMap(token -> this.profile(token, authentication)); }  @Override Maybe<User> loadUserByUsername(Authentication authentication); }
FacebookAuthenticationProvider extends AbstractSocialAuthenticationProvider<FacebookIdentityProviderConfiguration> { @Override public Maybe<User> loadUserByUsername(Authentication authentication) { return authenticate(authentication) .flatMap(token -> this.profile(token, authentication)); }  @Override Maybe<User> loadUserByUsername(Authentication authentication);  }