我想以编程方式列出和控制Azure中的经典(旧版)虚拟机.对于托管它没有问题,有库和其余的API正在工作,但一旦我调用旧API列出经典,我得到403(禁止).
代码好吗?我是否需要在其他地方管理旧API的凭据?
我的代码在这里:
static void Main(string[] args)
{
string apiNew = "https://management.azure.com/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxx/providers/Microsoft.Compute/virtualMachines?api-version=2018-06-01";
string apiOld = "https://management.core.windows.net/xxxxxxxxxxxxxxxxxxxxxxxx/services/vmimages"
AzureRestClient client = new AzureRestClient(credentials.TenantId, credentials.ClientId, credentials.ClientSecret);
//OK - I can list the managed VMs.
string resultNew = client.GetRequestAsync(apiNew).Result;
// 403 forbidden
string resultOld = client.GetRequestAsync(apiOld).Result;
}
public class AzureRestClient : IDisposable
{
private readonly HttpClient _client;
public AzureRestClient(string tenantName, string clientId, string clientSecret)
{
_client = CreateClient(tenantName, clientId, clientSecret).Result;
}
private async Task<string> GetAccessToken(string tenantName, string clientId, string clientSecret)
{
string …Run Code Online (Sandbox Code Playgroud) 根据此文档:应用程序和服务主体显然是两个不同的事物。应用程序是全局标识,服务主体是每个租户/ AAD
为了使其更加混乱,当我使用Graph API(来自第一个参考文献)并按我的应用程序名称查询时:
https://graph.windows.net/<tenantName>/applications?api-version=1.6&$filter=displayName eq '<Apllication Name>'
Run Code Online (Sandbox Code Playgroud)
我看到一个对象ID,一个应用程序ID(我认为是相同的),但Json中没有服务主体ID
AppID和ServicePrincipalID(以及ClientID,ObjectID)之间是什么关系?谢谢。
azure-active-directory azure-ad-graph-api azure-security azure-authentication
我正在尝试使用 AZ AD CLI 删除许多具有类似属性的应用程序。我找不到任何好的例子--filter
试图做这样的事情:
ad az app list --filter (displayName like 'stack') | ad az app delete
Run Code Online (Sandbox Code Playgroud)
任何指针都非常感谢。
我有一个包含大约 20 万用户的目录。我需要撤回来自本地 AD 的所有用户。这当然会排除多个源来宾用户。我必须使用源,因为并非所有用户都有用户类型。
如果有一种方法可以搜索 Department 不等于 null 也可以,但它似乎不是 odata 过滤器标准的一部分。
Get-AzureADUser -Filter "Department eq ''" | select DisplayName,`
UserPrincipalName,Mail,creationType,AccountEnabled,Department
Run Code Online (Sandbox Code Playgroud) 我有一个运行时间很长的进程,该进程使用Azure Function App(针对长时间运行的进程)托管(针对v2.0)。之前它的目标是v1.0运行时,所以我没有遇到任何函数超时问题。
但是现在在将运行时更新为目标v2.0之后,我无法找到任何方法来将函数超时设置为Infinite(与v1.0一样)。
有人可以帮我吗?
我是天蓝色 AD 的新手。
我有一个第三方 API,它为我提供了 userId。我编写了一个 .NET Core API,它应该采用此用户 ID 并获取该特定用户的角色和组。
我读过有关 microsoft graph API 的内容。不确定这在我的场景中是否有用。
还有其他方法可以以编程方式访问 AD 用户的角色和组吗?
我想使用 Azure Logic App 构建应用程序注册流程(用于自动化)
如何在 Azure AD 中自动注册应用程序?进行 REST API 调用应该简单直接,有人知道如何进行应用程序注册的 POST 吗?
很少有例子将不胜感激。
除了 Azure 逻辑应用程序支持的 REST API 之外,任何其他方式也非常受欢迎!
我正在尝试获取特定用户定义身份的 msi 令牌。我们的应用服务有 2 个用户定义的身份,我想要一个代表用户分配的身份之一的令牌。
这是代码:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(
"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/&object_id=<ObjectId>&client_id=<clientId>");
req.Headers["Metadata"] = "true";
req.Method = "GET";
try
{
// Call /token endpoint
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
// Pipe response Stream to a StreamReader, and extract access token
StreamReader streamResponse = new StreamReader(response.GetResponseStream());
string stringResponse = streamResponse.ReadToEnd();
Dictionary<string, string> list =
JsonConvert.DeserializeObject<Dictionary<string, string>>(stringResponse);
string accessToken = list["access_token"];
System.IO.File.WriteAllText(@".\Log.txt", accessToken);
}
catch (Exception e)
{
string errorText = String.Format("{0} \n\n{1}", e.Message, e.InnerException != null ? e.InnerException.Message : "Acquire token failed");
System.IO.File.WriteAllText(@".\Log.txt", …Run Code Online (Sandbox Code Playgroud) azure azure-active-directory azure-web-app-service azure-managed-identity
设置规格
Startup.cs配置
// COOKIES: Tells it to use cookies for authentication.
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
CookieManager = new SystemWebCookieManager()
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions()
{
ClientId = ClientID,
Authority = Authority,
PostLogoutRedirectUri = PostLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications()
{
AuthenticationFailed = PrincipalService.OnAzureAuthenticationFailure,
AuthorizationCodeReceived = (AuthorizationCodeReceivedNotification notification) =>
{
var username = notification.AuthenticationTicket.Identity.Name.Split('#').LastOrDefault();
var emailAddress = notification.AuthenticationTicket.Identity.Claims.FirstOrDefault(x => x.Type.Contains("emailaddress"))?.Value;
Logger.Log(Level.Auth, $"Azure login success! Username: '{username}' Email: '{emailAddress}'.");
return Task.FromResult(0);
}
}
});
Run Code Online (Sandbox Code Playgroud)
题
在进行此设置后,如何检查当前登录的用户是否在特定的AD组中? …