Skip to content

Commit

Permalink
Merge pull request #814 from AzureAD/avdunn/cloudshell-request-fix
Browse files Browse the repository at this point in the history
Change Cloudshell request method from POST to GET
  • Loading branch information
Avery-Dunn authored Jul 22, 2024
2 parents c1ca9ff + eeee815 commit d3faa28
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,9 @@ public ManagedIdentityResponse getManagedIdentityResponse(
IHttpResponse response;

try {

HttpRequest httpRequest = managedIdentityRequest.method.equals(HttpMethod.GET) ?
new HttpRequest(HttpMethod.GET,
managedIdentityRequest.computeURI().toString(),
managedIdentityRequest.headers) :
new HttpRequest(HttpMethod.POST,
HttpRequest httpRequest = new HttpRequest(managedIdentityRequest.method,
managedIdentityRequest.computeURI().toString(),
managedIdentityRequest.headers,
managedIdentityRequest.getBodyAsString());
managedIdentityRequest.headers);
response = serviceBundle.getHttpHelper().executeHttpRequest(httpRequest, managedIdentityRequest.requestContext(), serviceBundle);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ class CloudShellManagedIdentitySource extends AbstractManagedIdentitySource{
@Override
public void createManagedIdentityRequest(String resource) {
managedIdentityRequest.baseEndpoint = msiEndpoint;
managedIdentityRequest.method = HttpMethod.POST;
managedIdentityRequest.method = HttpMethod.GET;

managedIdentityRequest.headers = new HashMap<>();
managedIdentityRequest.headers.put("ContentType", "application/x-www-form-urlencoded");
managedIdentityRequest.headers.put("Metadata", "true");
managedIdentityRequest.headers.put("resource", resource);

managedIdentityRequest.bodyParameters = new HashMap<>();
managedIdentityRequest.bodyParameters.put("resource", Collections.singletonList(resource));
managedIdentityRequest.queryParameters = new HashMap<>();
managedIdentityRequest.queryParameters.put("resource", Collections.singletonList(resource));
}

private CloudShellManagedIdentitySource(MsalRequest msalRequest, ServiceBundle serviceBundle, URI msiEndpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ private HttpRequest expectedRequest(ManagedIdentitySourceType source, String res

headers.put("ContentType", "application/x-www-form-urlencoded");
headers.put("Metadata", "true");
headers.put("resource", resource);

bodyParameters.put("resource", Collections.singletonList(resource));
return new HttpRequest(HttpMethod.POST, computeUri(endpoint, queryParameters), headers, URLUtils.serializeParameters(bodyParameters));

queryParameters.put("resource", Collections.singletonList(resource));
return new HttpRequest(HttpMethod.GET, computeUri(endpoint, queryParameters), headers, URLUtils.serializeParameters(bodyParameters));
}
case IMDS: {
endpoint = IMDS_ENDPOINT;
Expand Down

0 comments on commit d3faa28

Please sign in to comment.