Skip to content

Commit 4d760c4

Browse files
authored
use metadata service to grab JWT token (#298) (#371)
1 parent ac91c74 commit 4d760c4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

azure-servicebus/src/main/java/com/microsoft/azure/servicebus/security/ManagedServiceIdentityTokenProvider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ public class ManagedServiceIdentityTokenProvider extends TokenProvider
2525
{
2626
private static final Logger TRACE_LOGGER = LoggerFactory.getLogger(ManagedServiceIdentityTokenProvider.class);
2727

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

@@ -72,14 +71,15 @@ private static MSIToken getMSIToken(String audience) throws IOException
7271
HttpURLConnection httpConnection;
7372
if(useStaticHttpUrl)
7473
{
75-
String localMSIURLForResouce = String.format(STATIC_MSI_URL_FORMAT, STATIC_LOCAL_REST_MSI_ENDPOINT_URL, audience);
74+
String localMSIURLForResouce =
75+
String.format(MSI_URL_FORMAT, STATIC_LOCAL_REST_MSI_ENDPOINT_URL, audience, APIVERSION);
7676
URL msiURL = new URL(localMSIURLForResouce);
7777
httpConnection = (HttpURLConnection) msiURL.openConnection();
7878
httpConnection.setRequestProperty(METADATA_HEADER_NAME, "true");
7979
}
8080
else
8181
{
82-
String localMSIURLForResouce = String.format(DYNAMIC_MSI_URL_FORMAT, localMsiEndPointURL, audience, APIVERSION);
82+
String localMSIURLForResouce = String.format(MSI_URL_FORMAT, localMsiEndPointURL, audience, APIVERSION);
8383
URL msiURL = new URL(localMSIURLForResouce);
8484
httpConnection = (HttpURLConnection) msiURL.openConnection();
8585
httpConnection.setRequestProperty(SECRET_HEADER_NAME, msiSecret);

0 commit comments

Comments
 (0)