Question 51 of 179 from exam AZ-204: Developing Solutions for Microsoft Azure

Question 51 of 179 from exam AZ-204: Developing Solutions for Microsoft Azure

Question

DRAG DROP - You are developing a web service that will run on Azure virtual machines that use Azure Storage.

You configure all virtual machines to use managed identities.

You have the following requirements: -> Secret-based authentication mechanisms are not permitted for accessing an Azure Storage account.

-> Must use only Azure Instance Metadata Service endpoints.

You need to write code to retrieve an access token to access Azure Storage.

To answer, drag the appropriate code segments to the correct locations.

Each code segment may be used once or not at all.

You may need to drag the split bar between panes or scroll to view content.

NOTE: Each correct selection is worth one point.

Select and Place:

Code segment 1

http: //localhost :50342/oauth2/token

http: //169.254.169.254:58432/oauth2/token

http: //localhost/metadata/identity/oauth2/token

http: //169.254.169.254/metadata/identity/oauth2/token

Code segment 2

XDocument.Parse(payload);

new MultipartContent(payload) ;

new NetworkCredential(“Azure”, payload);

IsonConvert .DeserializeObject<Dictionary<string, string>>(payload) ;

Answer Area

aia: Code segment 1

var queryString = ”
ver client = new wetpCLient()s

var response = await client.GetAsync(url + queryString);
var payload = await response.Content.ReadAsStringAsync();

return Code segment 2

Explanations

Code segment 1

http: //localhost :50342/oauth2/token

http: //169.254.169.254:50432/oauth2/token

http: //localhost/metadata/identity/oauth2/token

Code segment 2

XDocument.Parse(payload);

new MultipartContent(payload) ;

new NetworkCredential(“Azure”, payload);

Answer Area

var url =

var queryString ="

http: //169.2: 54 /metadata/ identity /oauth2/token

var client = new HttpClient();
var response = await client.GetAsync(url + queryString);
var payload = await response.Content.ReadAsStringAsync();

return

IsonConvert .DeserializeObjectDictionary<string, string>>(payload);

Azure Instance Metadata Service endpoints "/oauth2/token" Box 1: http://169.254.169.254/metadata/identity/oauth2/token Sample request using the Azure Instance Metadata Service (IMDS) endpoint (recommended): GET 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&amp;amp;resource=https://management.azure.com/' HTTP/1.1 Metadata: true Box 2: JsonConvert.DeserializeObject&amp;lt;Dictionary&amp;lt;string,string&amp;gt;&amp;gt;(payload); Deserialized token response; returning access code.

https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-token https://docs.microsoft.com/en-us/azure/service-fabric/how-to-managed-identity-service-fabric-app-code