protected AbstractAuthSupplier(String type) { clientAccessToken = new ClientAccessToken(); clientAccessToken.setTokenType(type); } public void setAccessToken(String accessToken) {
protected AbstractAuthSupplier(String type) { clientAccessToken = new ClientAccessToken(); clientAccessToken.setTokenType(type); } public void setAccessToken(String accessToken) {
ClientAccessToken token = new ClientAccessToken( tokenType, map.remove(OAuthConstants.ACCESS_TOKEN));
ClientAccessToken token = new ClientAccessToken( tokenType, map.remove(OAuthConstants.ACCESS_TOKEN));
private UserInfo getUserInfo( final String endpoint, final String accessToken, final IdToken idToken, final Consumer consumer) { WebClient userInfoServiceClient = WebClient.create(endpoint, Arrays.asList(new JsonMapObjectProvider())). accept(MediaType.APPLICATION_JSON); ClientAccessToken clientAccessToken = new ClientAccessToken(OAuthConstants.BEARER_AUTHORIZATION_SCHEME, accessToken); UserInfoClient userInfoClient = new UserInfoClient(); userInfoClient.setUserInfoServiceClient(userInfoServiceClient); UserInfo userInfo = null; try { userInfo = userInfoClient.getUserInfo(clientAccessToken, idToken, consumer); } catch (Exception e) { LOG.error("While getting the userInfo", e); SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Unknown); sce.getElements().add(e.getMessage()); throw sce; } return userInfo; }
protected ClientAccessToken getAccessToken() { if (getAccessTokenString() != null) { // if we have access_token directly, use it return new ClientAccessToken(OAuthConstants.ACCESS_TOKEN_TYPE, getAccessTokenString()); } Consumer consumer = new Consumer(getClientId(), getClientSecret()); WebClient client = WebClient.create(getAccessTokenURI()); RefreshTokenGrant grant = new RefreshTokenGrant(getRefreshToken()); return OAuthClientUtils.getAccessToken(client, consumer, grant, null, "Bearer", false); }
protected ClientAccessToken getAccessToken() { if (getAccessTokenString() != null) { // if we have access_token directly, use it return new ClientAccessToken(OAuthConstants.ACCESS_TOKEN_TYPE, getAccessTokenString()); } Consumer consumer = new Consumer(getClientId(), getClientSecret()); WebClient client = WebClient.create(getAccessTokenURI()); RefreshTokenGrant grant = new RefreshTokenGrant(getRefreshToken()); return OAuthClientUtils.getAccessToken(client, consumer, grant, null, "Bearer", false); }
public static ClientAccessToken toClientAccessToken(ServerAccessToken serverToken, boolean supportOptionalParams) { String tokenKey = serverToken.getEncodedToken() != null ? serverToken.getEncodedToken() : serverToken.getTokenKey(); ClientAccessToken clientToken = new ClientAccessToken(serverToken.getTokenType(), tokenKey); clientToken.setRefreshToken(serverToken.getRefreshToken()); if (supportOptionalParams) { clientToken.setExpiresIn(serverToken.getExpiresIn()); List<OAuthPermission> perms = serverToken.getScopes(); String scopeString = OAuthUtils.convertPermissionsToScope(perms); if (!StringUtils.isEmpty(scopeString)) { clientToken.setApprovedScope(scopeString); } clientToken.setParameters(new HashMap<String, String>(serverToken.getParameters())); } return clientToken; }
public static ClientAccessToken toClientAccessToken(ServerAccessToken serverToken, boolean supportOptionalParams) { String tokenKey = serverToken.getEncodedToken() != null ? serverToken.getEncodedToken() : serverToken.getTokenKey(); ClientAccessToken clientToken = new ClientAccessToken(serverToken.getTokenType(), tokenKey); clientToken.setRefreshToken(serverToken.getRefreshToken()); if (supportOptionalParams) { clientToken.setExpiresIn(serverToken.getExpiresIn()); List<OAuthPermission> perms = serverToken.getScopes(); String scopeString = OAuthUtils.convertPermissionsToScope(perms); if (!StringUtils.isEmpty(scopeString)) { clientToken.setApprovedScope(scopeString); } clientToken.setParameters(new HashMap<String, String>(serverToken.getParameters())); } return clientToken; }
@Test public void testRegisterClientTwoWayTLSClientIdBoundDynReg() throws Exception { String dynRegAddress = "https://localhost:" + PORT + "/oauth2Jwt/register"; WebClient wcDynReg = createDynRegWebClient(dynRegAddress); wcDynReg.accept("application/json").type("application/json"); ClientRegistration reg = newClientRegistration(); wcDynReg.authorization(new ClientAccessToken("Bearer", "123456789")); ClientRegistrationResponse resp = wcDynReg.post(reg, ClientRegistrationResponse.class); doTestTwoWayTLSClientIdBoundJwt(resp.getClientId()); // delete the client String regAccessToken = resp.getRegistrationAccessToken(); assertNotNull(regAccessToken); wcDynReg.path(resp.getClientId()); wcDynReg.authorization(new ClientAccessToken("Bearer", regAccessToken)); assertEquals(200, wcDynReg.delete().getStatus()); assertNotNull(regAccessToken); }
@org.junit.Test public void testRegisterClientInitialAccessTokenCodeGrant() throws Exception { URL busFile = OIDCDynamicRegistrationTest.class.getResource("client.xml"); String address = "https://localhost:" + PORT + "/services/dynamicWithAt/register"; WebClient wc = WebClient.create(address, Collections.singletonList(new JsonMapObjectProvider()), busFile.toString()); wc.accept("application/json").type("application/json"); ClientRegistration reg = newClientRegistrationCodeGrant(); ClientRegistrationResponse resp = null; assertEquals(401, wc.post(reg).getStatus()); wc.authorization(new ClientAccessToken("Bearer", "123456789")); resp = wc.post(reg, ClientRegistrationResponse.class); assertNotNull(resp.getClientId()); assertNotNull(resp.getClientSecret()); assertEquals(address + "/" + resp.getClientId(), resp.getRegistrationClientUri()); String regAccessToken = resp.getRegistrationAccessToken(); assertNotNull(regAccessToken); wc.reset(); wc.path(resp.getClientId()); assertEquals(401, wc.get().getStatus()); wc.authorization(new ClientAccessToken("Bearer", regAccessToken)); ClientRegistration clientRegResp = wc.get(ClientRegistration.class); testCommonRegCodeGrantProperties(clientRegResp); assertNull(clientRegResp.getTokenEndpointAuthMethod()); assertEquals(200, wc.delete().getStatus()); }
assertEquals(401, wc.post(reg).getStatus()); wc.authorization(new ClientAccessToken("Bearer", "123456789")); resp = wc.post(reg, ClientRegistrationResponse.class); assertEquals(401, wc.get().getStatus()); wc.authorization(new ClientAccessToken("Bearer", regAccessToken)); ClientRegistration clientRegResp = wc.get(ClientRegistration.class); testCommonRegCodeGrantProperties(clientRegResp);
reg.setGrantTypes(Collections.singletonList(OAuthConstants.RESOURCE_OWNER_GRANT)); wc.authorization(new ClientAccessToken("Bearer", "123456789")); ClientRegistrationResponse resp = wc.post(reg, ClientRegistrationResponse.class); wc.path(resp.getClientId()); wc.authorization(new ClientAccessToken("Bearer", regAccessToken)); ClientRegistration clientRegResp = wc.get(ClientRegistration.class); assertEquals("web", clientRegResp.getApplicationType());
reg.setGrantTypes(Collections.singletonList(OAuthConstants.RESOURCE_OWNER_GRANT)); reg.setTokenEndpointAuthMethod(OAuthConstants.TOKEN_ENDPOINT_AUTH_NONE); wc.authorization(new ClientAccessToken("Bearer", "123456789")); ClientRegistrationResponse resp = wc.post(reg, ClientRegistrationResponse.class); wc.path(resp.getClientId()); wc.authorization(new ClientAccessToken("Bearer", regAccessToken)); ClientRegistration clientRegResp = wc.get(ClientRegistration.class); assertEquals("native", clientRegResp.getApplicationType());