use of com.oauth.server.dto.OAuthClientDetails in project alexa-oauth-sample by alexa-samples.
the class SampleDataLoader method loadSampleData.
public void loadSampleData() {
OAuthClientDetails testAlexaClient = OAuthClientDetails.builder().clientId("test_alexa_client").clientSecret(passwordEncoder.encode("test_client_secret")).scopes("profile").webServerRedirectUri("https://pitangui.amazon.com/api/skill/link/M3KVOEXUO4ALBL").accessTokenValidity(3600).refreshTokenValidity(0).authorizedGrantTypes("implicit,authorization_code,refresh_token").build();
OAuthClientDetails adminClient = OAuthClientDetails.builder().clientId("test_admin_client").clientSecret(passwordEncoder.encode("test_client_secret")).scopes("test_scope").webServerRedirectUri("http://localhost:5000/redirect").accessTokenValidity(3600).refreshTokenValidity(0).authorities(RoleEnum.ROLE_CLIENT_ADMIN.name()).authorizedGrantTypes("client_credentials,implicit,authorization_code,password,refresh_token").build();
OAuthPartner testAlexaPartner = OAuthPartner.builder().partnerId("test_alexa_client").clientId("amzn1.application-oa2-client.0897266ee6fb480ead86d615e2653558").clientSecret("8241c286e8eb9c9741ce5b9e009c892f0bd4d603b21e51dc37efb5981245191a").scopes("alexa::health:profile:write").accessTokenUri("https://api.amazon.com/auth/o2/token").userAuthorizationUri("https://www.amazon.com/ap/oa").preEstablishedRedirectUri("").build();
dynamoDBMapper.batchSave(ImmutableList.of(testAlexaClient, adminClient, testAlexaPartner));
}
use of com.oauth.server.dto.OAuthClientDetails in project alexa-oauth-sample by alexa-samples.
the class DynamoDBClientDetailsDAO method addOrUpdateClientDetails.
/**
* Add or update a client details in database.
*
* @param clientDetails client details.
*/
public void addOrUpdateClientDetails(@NonNull ClientDetails clientDetails) {
List<String> autoApproveList = clientDetails.getScope().stream().filter(scope -> clientDetails.isAutoApprove(scope)).collect(Collectors.toList());
OAuthClientDetails oAuthClientDetails = OAuthClientDetails.builder().clientId(clientDetails.getClientId()).authorities(StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorities())).authorizedGrantTypes(StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorizedGrantTypes())).scopes(StringUtils.collectionToCommaDelimitedString(clientDetails.getScope())).webServerRedirectUri(StringUtils.collectionToCommaDelimitedString(clientDetails.getRegisteredRedirectUri())).accessTokenValidity(clientDetails.getAccessTokenValiditySeconds()).refreshTokenValidity(clientDetails.getRefreshTokenValiditySeconds()).autoapprove(StringUtils.collectionToCommaDelimitedString(autoApproveList)).build();
DynamoDBMapperConfig dynamoDBMapperConfig = DynamoDBMapperConfig.builder().withSaveBehavior(SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES).build();
dynamoDBMapper.save(oAuthClientDetails, dynamoDBMapperConfig);
}
use of com.oauth.server.dto.OAuthClientDetails in project alexa-oauth-sample by alexa-samples.
the class DynamoDBClientDetailsDAO method addClientDetails.
/**
* Add a new {@link ClientDetails} into Database.
*
* @param clientDetails client details to be added.
* @throws ClientAlreadyExistsException if client details already exists.
*/
@Override
public void addClientDetails(ClientDetails clientDetails) throws ClientAlreadyExistsException {
OAuthClientDetails oAuthClientDetails = dynamoDBMapper.load(OAuthClientDetails.class, clientDetails.getClientId());
if (oAuthClientDetails != null) {
throw new ClientAlreadyExistsException("client already exists: " + clientDetails.getClientId());
}
addOrUpdateClientDetails(clientDetails);
}
use of com.oauth.server.dto.OAuthClientDetails in project alexa-oauth-sample by alexa-samples.
the class DynamoDBClientDetailsDAO method updateClientDetails.
/**
* Update an existing {@link ClientDetails} in database.
*
* @param clientDetails client details.
* @throws NoSuchClientException if client not exit.
*/
@Override
public void updateClientDetails(@NonNull ClientDetails clientDetails) throws NoSuchClientException {
OAuthClientDetails oAuthClientDetails = dynamoDBMapper.load(OAuthClientDetails.class, clientDetails.getClientId());
if (oAuthClientDetails == null) {
throw new NoSuchClientException("client not exists: " + clientDetails.getClientId());
}
addOrUpdateClientDetails(clientDetails);
}
use of com.oauth.server.dto.OAuthClientDetails in project alexa-oauth-sample by alexa-samples.
the class DynamoDBClientDetailsDAO method updateClientSecret.
/**
* Update the client secret for a specific client id.
*
* @param clientId client id.
* @param secret client secret.
* @throws NoSuchClientException if client not exist.
*/
@Override
public void updateClientSecret(@NonNull String clientId, @NonNull String secret) throws NoSuchClientException {
OAuthClientDetails oAuthClientDetails = dynamoDBMapper.load(OAuthClientDetails.class, clientId);
if (oAuthClientDetails == null) {
throw new NoSuchClientException("client not exists: " + clientId);
}
OAuthClientDetails updatedItem = oAuthClientDetails.toBuilder().clientSecret(passwordEncoder.encode(secret)).build();
dynamoDBMapper.save(updatedItem);
}
Aggregations