-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathAzureAuthorityHosts.cs
70 lines (61 loc) · 2.71 KB
/
AzureAuthorityHosts.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace Azure.Identity
{
/// <summary>
/// Defines fields exposing the well known authority hosts for the Azure Public Cloud and sovereign clouds.
/// </summary>
public static class AzureAuthorityHosts
{
private const string AzurePublicCloudHostUrl = "https://login.microsoftonline.com/";
private const string AzureChinaHostUrl = "https://login.chinacloudapi.cn/";
private const string AzureGermanyHostUrl = "https://login.microsoftonline.de/";
private const string AzureGovernmentHostUrl = "https://login.microsoftonline.us/";
/// <summary>
/// The host of the Microsoft Entra authority for tenants in the Azure Public Cloud.
/// </summary>
public static Uri AzurePublicCloud { get; } = new Uri(AzurePublicCloudHostUrl);
/// <summary>
/// The host of the Microsoft Entra authority for tenants in the Azure China Cloud.
/// </summary>
public static Uri AzureChina { get; } = new Uri(AzureChinaHostUrl);
/// <summary>
/// The host of the Microsoft Entra authority for tenants in the Azure German Cloud.
/// </summary>
public static Uri AzureGermany { get; } = new Uri(AzureGermanyHostUrl);
/// <summary>
/// The host of the Microsoft Entra authority for tenants in the Azure US Government Cloud.
/// </summary>
public static Uri AzureGovernment { get; } = new Uri(AzureGovernmentHostUrl);
internal static Uri GetDefault()
{
if (EnvironmentVariables.AuthorityHost != null)
{
return new Uri(EnvironmentVariables.AuthorityHost);
}
return AzurePublicCloud;
}
internal static string GetDefaultScope(Uri authorityHost)
{
switch (authorityHost.AbsoluteUri)
{
case AzurePublicCloudHostUrl:
// The double slash is intentional for public cloud.
return "https://management.azure.com//.default";
case AzureChinaHostUrl:
return "https://management.chinacloudapi.cn/.default";
case AzureGermanyHostUrl:
return "https://management.microsoftazure.de/.default";
case AzureGovernmentHostUrl:
return "https://management.usgovcloudapi.net/.default";
default:
return null;
}
}
internal static Uri GetDeviceCodeRedirectUri(Uri authorityHost)
{
return new Uri(authorityHost, "/common/oauth2/nativeclient");
}
}
}