forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Azure#13687: Move to latest App Services MSI API version
- Loading branch information
1 parent
a665460
commit 2a19fae
Showing
13 changed files
with
426 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
sdk/identity/Azure.Identity/src/AppServiceV2017AuthRequestBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Azure.Core; | ||
using Azure.Core.Pipeline; | ||
|
||
namespace Azure.Identity | ||
{ | ||
internal class AppServiceV2017AuthRequestBuilder : IAuthRequestBuilder | ||
{ | ||
// MSI Constants. Docs for MSI are available here https://docs.microsoft.com/en-us/azure/app-service/overview-managed-identity | ||
private const string AppServiceMsiApiVersion = "2017-09-01"; | ||
|
||
private readonly HttpPipeline _pipeline; | ||
private readonly Uri _endpoint; | ||
private readonly string _secret; | ||
private readonly string _clientId; | ||
|
||
public AppServiceV2017AuthRequestBuilder(HttpPipeline pipeline, Uri endpoint, string secret, string clientId) | ||
{ | ||
_pipeline = pipeline; | ||
_endpoint = endpoint; | ||
_secret = secret; | ||
_clientId = clientId; | ||
} | ||
|
||
public Request CreateRequest(string[] scopes) | ||
{ | ||
// covert the scopes to a resource string | ||
string resource = ScopeUtilities.ScopesToResource(scopes); | ||
|
||
Request request = _pipeline.CreateRequest(); | ||
|
||
request.Method = RequestMethod.Get; | ||
request.Headers.Add("secret", _secret); | ||
request.Uri.Reset(_endpoint); | ||
request.Uri.AppendQuery("api-version", AppServiceMsiApiVersion); | ||
request.Uri.AppendQuery("resource", resource); | ||
|
||
if (!string.IsNullOrEmpty(_clientId)) | ||
{ | ||
request.Uri.AppendQuery("clientid", _clientId); | ||
} | ||
|
||
return request; | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
sdk/identity/Azure.Identity/src/AppServiceV2019AuthRequestBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Azure.Core; | ||
using Azure.Core.Pipeline; | ||
|
||
namespace Azure.Identity | ||
{ | ||
internal class AppServiceV2019AuthRequestBuilder : IAuthRequestBuilder | ||
{ | ||
private const string AppServiceMsiApiVersion = "2019-08-01"; | ||
|
||
private readonly HttpPipeline _pipeline; | ||
private readonly Uri _endpoint; | ||
private readonly string _secret; | ||
private readonly string _clientId; | ||
|
||
public AppServiceV2019AuthRequestBuilder(HttpPipeline pipeline, Uri endpoint, string secret, string clientId) | ||
{ | ||
_pipeline = pipeline; | ||
_endpoint = endpoint; | ||
_secret = secret; | ||
_clientId = clientId; | ||
} | ||
|
||
public Request CreateRequest(string[] scopes) | ||
{ | ||
// covert the scopes to a resource string | ||
string resource = ScopeUtilities.ScopesToResource(scopes); | ||
|
||
Request request = _pipeline.CreateRequest(); | ||
|
||
request.Method = RequestMethod.Get; | ||
request.Headers.Add("X-IDENTITY-HEADER", _secret); | ||
request.Uri.Reset(_endpoint); | ||
request.Uri.AppendQuery("api-version", AppServiceMsiApiVersion); | ||
request.Uri.AppendQuery("resource", resource); | ||
|
||
if (!string.IsNullOrEmpty(_clientId)) | ||
{ | ||
request.Uri.AppendQuery("client_id", _clientId); | ||
} | ||
|
||
return request; | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
sdk/identity/Azure.Identity/src/CloudShellAuthRequestBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Text; | ||
using Azure.Core; | ||
using Azure.Core.Pipeline; | ||
|
||
namespace Azure.Identity | ||
{ | ||
internal class CloudShellAuthRequestBuilder : IAuthRequestBuilder | ||
{ | ||
private readonly HttpPipeline _pipeline; | ||
private readonly Uri _endpoint; | ||
private readonly string _clientId; | ||
|
||
public CloudShellAuthRequestBuilder(HttpPipeline pipeline, Uri endpoint, string clientId) | ||
{ | ||
_pipeline = pipeline; | ||
_endpoint = endpoint; | ||
_clientId = clientId; | ||
} | ||
|
||
public Request CreateRequest(string[] scopes) | ||
{ | ||
// covert the scopes to a resource string | ||
string resource = ScopeUtilities.ScopesToResource(scopes); | ||
|
||
Request request = _pipeline.CreateRequest(); | ||
|
||
request.Method = RequestMethod.Post; | ||
|
||
request.Headers.Add(HttpHeader.Common.FormUrlEncodedContentType); | ||
|
||
request.Uri.Reset(_endpoint); | ||
|
||
request.Headers.Add("Metadata", "true"); | ||
|
||
var bodyStr = $"resource={Uri.EscapeDataString(resource)}"; | ||
|
||
if (!string.IsNullOrEmpty(_clientId)) | ||
{ | ||
bodyStr += $"&client_id={Uri.EscapeDataString(_clientId)}"; | ||
} | ||
|
||
ReadOnlyMemory<byte> content = Encoding.UTF8.GetBytes(bodyStr).AsMemory(); | ||
request.Content = RequestContent.Create(content); | ||
return request; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Azure.Core; | ||
|
||
namespace Azure.Identity | ||
{ | ||
internal interface IAuthRequestBuilder | ||
{ | ||
Request CreateRequest(string[] scopes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Azure.Core; | ||
using Azure.Core.Pipeline; | ||
|
||
namespace Azure.Identity | ||
{ | ||
internal class ImdsAuthRequestBuilder : IAuthRequestBuilder | ||
{ | ||
private const string ImdsApiVersion = "2018-02-01"; | ||
|
||
private readonly HttpPipeline _pipeline; | ||
private readonly Uri _endpoint; | ||
private readonly string _clientId; | ||
|
||
public ImdsAuthRequestBuilder(HttpPipeline pipeline, Uri endpoint, string clientId) | ||
{ | ||
_pipeline = pipeline; | ||
_clientId = clientId; | ||
_endpoint = endpoint; | ||
} | ||
|
||
public Request CreateRequest(string[] scopes) | ||
{ | ||
// covert the scopes to a resource string | ||
string resource = ScopeUtilities.ScopesToResource(scopes); | ||
|
||
Request request = _pipeline.CreateRequest(); | ||
request.Method = RequestMethod.Get; | ||
request.Headers.Add("Metadata", "true"); | ||
request.Uri.Reset(_endpoint); | ||
request.Uri.AppendQuery("api-version", ImdsApiVersion); | ||
|
||
request.Uri.AppendQuery("resource", resource); | ||
|
||
if (!string.IsNullOrEmpty(_clientId)) | ||
{ | ||
request.Uri.AppendQuery("client_id", _clientId); | ||
} | ||
|
||
return request; | ||
} | ||
} | ||
} |
Oops, something went wrong.