How to send GET request to Azure FHIR from Spring-boot?

Viewed 108

I am trying to send GET request to Azure API for FHIR using Spring Boot.
I have created an application having permission as "FHIR Data Contributor", and have its client-id, tenant-id and client-secret-value.
I have written the code below to get the access_token. It is returning the access_token, but how do I make use of the token and send GET request to FHIR ?

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;


@RestController
public class HelloController {
    
    @GetMapping("/token")
    @ResponseBody
    public String token(@RegisteredOAuth2AuthorizedClient("graph") OAuth2AuthorizedClient client) { 
        String accessToken=client.getAccessToken().getTokenValue();
        return accessToken; 
    }
    
    
}

The application.yml contains:

azure:
  activedirectory:
    tenant-id: XXXXXXX-xxxxx-XXXXXXXX
    client-id: XXXXXXX-xxxxx-XXXXXXXX
    client-secret: XXXXXXX-xxxxx-XXXXXXXX
    authorization-clients:
      graph:
        scopes: https://graph.microsoft.com/User.Read

I am able to do all this using Postman.

0 Answers
Related