Skip to content

Commit

Permalink
Convert to id_token instead of UAT; use terminology client token
Browse files Browse the repository at this point in the history
  • Loading branch information
scannillo committed Jun 3, 2020
1 parent a7f19a2 commit e954b0b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This repository represents a sample merchant server for a merchant integrating w
## Build and run locally
To build and run locally, use the command: `./mvnw spring-boot:run -Dspring-boot.run.profiles=local`. Running this command will install Maven and all necessary dependencies.

If everything worked, you should be able to hit `http://localhost:5000/uat?countryCode=US`.
If everything worked, you should be able to hit `http://localhost:5000/client-token?countryCode=US`.

## Switching Merchant Account/ Authentication

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
public class UniversalAccessToken {
public class IdToken {

private String token;

@JsonProperty("universal_access_token")
@JsonProperty("id_token")
public String getToken() {
return token;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public OrdersV2Client(RestTemplate restTemplate,

Order createOrder(CreateOrderRequest orderBody, String countryCode) {
HttpHeaders orderHeaders = new HttpHeaders();
orderHeaders.add("Authorization", "Bearer " + payPalTokenService.getFullScopedUAT(countryCode).getToken());
orderHeaders.add("Authorization", "Bearer " + payPalTokenService.getFullScopedToken(countryCode).getToken());
orderHeaders.setContentType(MediaType.APPLICATION_JSON);

HttpEntity<CreateOrderRequest> orderRequest = new HttpEntity<>(orderBody, orderHeaders);
Expand All @@ -45,7 +45,7 @@ Order createOrder(CreateOrderRequest orderBody, String countryCode) {

Order processOrder(ProcessOrderRequest processOrderRequest) {
HttpHeaders orderHeaders = new HttpHeaders();
orderHeaders.add("Authorization", "Bearer " + payPalTokenService.getFullScopedUAT(processOrderRequest.getCountryCode()).getToken());
orderHeaders.add("Authorization", "Bearer " + payPalTokenService.getFullScopedToken(processOrderRequest.getCountryCode()).getToken());
orderHeaders.setContentType(MediaType.APPLICATION_JSON);

HttpEntity<String> orderRequest = new HttpEntity<>("", orderHeaders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ public PayPalTokenClient(RestTemplate restTemplate, TokenUtil tokenUtil, @Value(
this.url = url;
}

public UniversalAccessToken getLowScopedUAT(final String countryCode) {
return getUAT(tokenUtil.getTokenAuthorizationHeaderForLowScope(countryCode));
public IdToken getLowScopedToken(final String countryCode) {
return getToken(tokenUtil.getTokenAuthorizationHeaderForLowScope(countryCode));
}

public UniversalAccessToken getFullScopedUAT(final String countryCode) {
return getUAT(tokenUtil.getTokenAuthorizationHeaderForFullScope(countryCode));
public IdToken getFullScopedToken(final String countryCode) {
return getToken(tokenUtil.getTokenAuthorizationHeaderForFullScope(countryCode));
}

private UniversalAccessToken getUAT(final String authorizationHeader) {
private IdToken getToken(final String authorizationHeader) {
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", authorizationHeader);
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
body.add("grant_type", "client_credentials");
body.add("response_type", "uat");
body.add("response_type", "id_token");

HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(body, headers);
ResponseEntity<UniversalAccessToken> response = restTemplate.postForEntity(
ResponseEntity<IdToken> response = restTemplate.postForEntity(
url + TOKEN_PATH,
request,
UniversalAccessToken.class);
IdToken.class);

System.out.println("Universal Access Token: " + response.getBody().getToken());
System.out.println("id_token: " + response.getBody().getToken());
return response.getBody();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public RestController(OrdersV2Client ordersV2Client, PayPalTokenClient payPalTok
this.payPalTokenClient = payPalTokenClient;
}

@GetMapping(path = "/uat")
UniversalAccessToken getUat(@RequestParam(value = "countryCode") String countryCode) {
@GetMapping(path = "/client-token")
IdToken getClientToken(@RequestParam(value = "countryCode") String countryCode) {
System.out.println("******************************");
System.out.println("REQUEST to /v1/oauth2/token:");
System.out.println("Country code: " + countryCode);
return payPalTokenClient.getLowScopedUAT(countryCode);
return payPalTokenClient.getLowScopedToken(countryCode);
}

@PostMapping(path = "/order")
Expand Down

0 comments on commit e954b0b

Please sign in to comment.