Skip to content

Commit

Permalink
use metadata service to grab JWT token (#298) (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
yvgopal authored Jun 21, 2019
1 parent ac91c74 commit 4d760c4
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ public class ManagedServiceIdentityTokenProvider extends TokenProvider
{
private static final Logger TRACE_LOGGER = LoggerFactory.getLogger(ManagedServiceIdentityTokenProvider.class);

private static final String STATIC_LOCAL_REST_MSI_ENDPOINT_URL = "http://localhost:50342/oauth2/token";
private static final String APIVERSION = "api-version=2017-09-01";
private static final String STATIC_LOCAL_REST_MSI_ENDPOINT_URL = "http://169.254.169.254/metadata/identity/oauth2/token";
private static final String APIVERSION = "api-version=2018-02-01";
private static final String MSI_ENDPOINT_ENV_VARIABLE = "MSI_ENDPOINT";
private static final String MSI_SECRET_ENV_VARIABLE = "MSI_SECRET";
private static final String STATIC_MSI_URL_FORMAT = "%s?resource=%s";
private static final String DYNAMIC_MSI_URL_FORMAT = "%s?resource=%s&%s";
private static final String MSI_URL_FORMAT = "%s?resource=%s&%s";
private static final String METADATA_HEADER_NAME = "Metadata";
private static final String SECRET_HEADER_NAME = "Secret";

Expand Down Expand Up @@ -72,14 +71,15 @@ private static MSIToken getMSIToken(String audience) throws IOException
HttpURLConnection httpConnection;
if(useStaticHttpUrl)
{
String localMSIURLForResouce = String.format(STATIC_MSI_URL_FORMAT, STATIC_LOCAL_REST_MSI_ENDPOINT_URL, audience);
String localMSIURLForResouce =
String.format(MSI_URL_FORMAT, STATIC_LOCAL_REST_MSI_ENDPOINT_URL, audience, APIVERSION);
URL msiURL = new URL(localMSIURLForResouce);
httpConnection = (HttpURLConnection) msiURL.openConnection();
httpConnection.setRequestProperty(METADATA_HEADER_NAME, "true");
}
else
{
String localMSIURLForResouce = String.format(DYNAMIC_MSI_URL_FORMAT, localMsiEndPointURL, audience, APIVERSION);
String localMSIURLForResouce = String.format(MSI_URL_FORMAT, localMsiEndPointURL, audience, APIVERSION);
URL msiURL = new URL(localMSIURLForResouce);
httpConnection = (HttpURLConnection) msiURL.openConnection();
httpConnection.setRequestProperty(SECRET_HEADER_NAME, msiSecret);
Expand Down

0 comments on commit 4d760c4

Please sign in to comment.