use of com.oauth.server.dto.OAuthPartner 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.OAuthPartner in project alexa-oauth-sample by alexa-samples.
the class ReciprocalAuthorizationEndpoint method postReciprocalCode.
@RequestMapping(value = "/api/reciprocal/authorize", method = RequestMethod.POST)
public void postReciprocalCode(@RequestBody @RequestParam final Map<String, String> parameters) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String grantType = parameters.get("grant_type");
// It is not the client_id we got from partner, but the client id we vend out to partner (partnerId).
String partnerId = parameters.get("client_id");
String authorizationCode = parameters.get("code");
if (!StringUtils.equals(grantType, GRANT_TYPE)) {
throw new UnsupportedGrantTypeException("Only reciprocal_authorization_code is supported in this endpoint");
}
OAuthPartner partner = partnerDetailsRepository.loadPartnerByPartnerId(partnerId);
if (partner == null) {
throw new NoSuchClientException("Invalid partner id: " + partnerId);
}
OAuth2ProtectedResourceDetails resourceDetails = partner.toProtectedResourceDetails();
AuthorizationCodeAccessTokenProvider tokenProvider = new AuthorizationCodeAccessTokenProvider();
tokenProvider.setStateMandatory(false);
OAuth2AccessToken accessToken = tokenProvider.obtainAccessToken(resourceDetails, createAccessTokenRequest(authorizationCode));
partnerTokenRepository.saveAccessToken(resourceDetails, auth, accessToken);
}
use of com.oauth.server.dto.OAuthPartner in project alexa-oauth-sample by alexa-samples.
the class PartnersController method showEditForm.
@RequestMapping(value = "/form", method = RequestMethod.GET)
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String showEditForm(@RequestParam(value = "partnerId", required = false) String partnerId, Model model) {
OAuthPartner partner;
if (partnerId != null) {
partner = partnerDetailsRepository.loadPartnerByPartnerId(partnerId);
} else {
partner = OAuthPartner.builder().build();
}
model.addAttribute("partner", partner);
return "partnerForm";
}
use of com.oauth.server.dto.OAuthPartner in project alexa-oauth-sample by alexa-samples.
the class PartnerTokenEndpoint method getPartnerToken.
/**
* Endpoint to retrieve a client token from ClientTokenService.
*/
@RequestMapping(value = "/api/partner/token")
public OAuth2AccessToken getPartnerToken(@RequestParam final Map<String, String> parameters) {
final String userID = parameters.get("user_id");
final String partnerId = parameters.get("partner_id");
OAuthPartner partner = partnerDetailsService.loadPartnerByPartnerId(partnerId);
if (partner == null) {
throw new InvalidClientException("Invalid partner id: " + partnerId);
}
OAuth2ProtectedResourceDetails resourceDetails = partner.toProtectedResourceDetails();
OAuth2AccessToken accessToken = partnerTokenService.getAccessToken(resourceDetails, new UserIDAuthenticationToken(userID));
if (accessToken == null) {
throw new OAuth2Exception("No token found for user: " + userID);
} else {
accessToken = refreshClientToken(accessToken, resourceDetails);
}
partnerTokenService.removeAccessToken(resourceDetails, new UserIDAuthenticationToken(userID));
partnerTokenService.saveAccessToken(resourceDetails, new UserIDAuthenticationToken(userID), accessToken);
return accessToken;
}
Aggregations