Retrieving data from a third-party API with OAuth

After having authenticated a user with OAuth2, it is useful to know how to call a remote third-party API with the user's OAuth2 account.

How to do it…

  1. You may have noticed that IndexController, StockProductController, ChartIndexController, and ChartStockController invoke underlying service methods named gather(…). This concept suggests that lookups to third-party providers (Yahoo!) are proceeded.
  2. In IndexServiceImpl, for example, you can find the gather(String indexId) method:
    @Override public Index gather(String indexId) { Index index = indexRepository.findOne(indexId); if(AuthenticationUtil.userHasRole(Role.ROLE_OAUTH2)){ updateIndexAndQuotesFromYahoo(index != null ? Sets.newHashSet(index) : Sets.newHashSet(new ...

Get Spring MVC: Designing Real-World Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.