In my current project, I create a service to get a token from Microsoft graph. Response from Microsoft like this.
{
"token_type": "Bearer",
"scope": "User.Read",
"expires_in": 4041,
"ext_expires_in": 4041,
"access_token": "${token}",
"refresh_token": "${refresh token}",
"id_token": "${id token}"
}
I create a class to serialize responses from Microsoft.
@Setter
@Getter
@Accessors(chain = true)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class ResponseMicrosoftAuthDto {
private String tokenType;
private String scope;
private int expiresIn;
private int extExpiresIn;
private String accessToken;
private String refreshToken;
private String idToken;
}
in my service, I make a request using RestTemplate.
public ResponseMicrosoftAuthDto loginToMicrosoftGraph(String username, String password) {
var url = "https://login.microsoftonline.com/${tenant id}/oauth2/v2.0/token";
HttpEntity<MultiValueMap<String, String>> requestEntity = createLoginMicrosoftRequest(username, password);
var restTemplate = new RestTemplate();
return restTemplate.postForObject(url, requestEntity, ResponseMicrosoftAuthDto.class);
}
I don't know why the refresh_token
and id_token
be null.