久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 Azure Active Directory .NET SDK 刪除 AppRoleAs

How do I delete an AppRoleAssignment using the Azure Active Directory .NET SDK?(如何使用 Azure Active Directory .NET SDK 刪除 AppRoleAssignment?)
本文介紹了如何使用 Azure Active Directory .NET SDK 刪除 AppRoleAssignment?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我試圖弄清楚如何使用 Azure Active Directory 的 Graph API 從組或用戶中刪除 AppRoleAssignment.我正在使用 .NET SDK (Microsoft.Azure.ActiveDirectory.GraphClient).

I'm trying to figure out how to delete an AppRoleAssignment from either an Group or a User using the Graph API for Azure Active Directory. I'm using the .NET SDK (Microsoft.Azure.ActiveDirectory.GraphClient).

我嘗試使用每個(gè) IEntityBase 上的標(biāo)準(zhǔn) DeleteAsync 方法,但它失敗并出現(xiàn)錯(cuò)誤.它發(fā)出一個(gè)如下所示的 HTTP 請(qǐng)求:

I've tried using the standard DeleteAsync method that's on every IEntityBase, but it fails with an error. It's issuing an HTTP request that looks like this:

DELETE/{tenantId}/directoryObjects/{appRoleAssignment ObjectID}/Microsoft.DirectoryServices.AppRoleAssignment?api-version=1.5

失敗并返回 400 Bad Request 并顯示錯(cuò)誤不支持直接查詢此資源類型."

which fails with a 400 Bad Request with the error "Direct queries to this resource type are not supported."

根據(jù) this Microsoft blog post 說(shuō)您需要執(zhí)行如下所示的 HTTP 請(qǐng)求:

This isn't the correct way to delete AppRoleAssignments using the Graph API according to this Microsoft blog post which says you need to do an HTTP request that looks like:

DELETE/{tenantId}/users/{user object ID}/appRoleAssignments/{appRoleAs}?api-version=1.5

如果我使用 HttpClient 使用該 URL 格式執(zhí)行手動(dòng) HTTP 請(qǐng)求,它可以工作,但我想知道如何在 .NET 庫(kù)的范圍內(nèi)執(zhí)行此操作,而不是自己執(zhí)行手動(dòng) HTTP 請(qǐng)求.

If I do a manual HTTP request using HttpClient using that URL format, it works, but I want to know how to do this within the bounds of the .NET library rather than doing manual HTTP requests myself.

如何通過(guò) .NET 庫(kù)刪除 AppRoleAssignments?

How do I delete AppRoleAssignments via the .NET library?

推薦答案

雖然不固定,但您可以手動(dòng)發(fā)出 HTTP 請(qǐng)求,但仍使用 Azure AD SDK 獲取令牌.像這樣的:

While it is not fixed, you can make a manual HTTP-request, but still using Azure AD SDK to acqure the token. Something like this:

var tenantId = "<guid> tenant id";
var appId = "<guid> your Azure app id";
var appKey = "your app key";
var authority = "i.e. https://login.windows.net/mycompany.onmicrosoft.com";
var graphUrl = "https://graph.windows.net/";

public async Task RemoveRoleFromUser(Guid userId, string roleObjectId) {
    var uri = string.Format("{0}/users/{1}/appRoleAssignments/{2}?api-version=1.5", tenantId, userId, roleObjectId);
    await ExecuteRequest<object>(uri, HttpMethod.Delete);
}

private async Task<T> ExecuteRequest<T>(string uri, HttpMethod method = null, Object body = null) where T : class {
    if (method == null) method = HttpMethod.Get;
    T response;
    var token = await AcquireTokenAsyncForApplication();
    using (var httpClient = new HttpClient { BaseAddress = getServicePointUri() }) {
        var request = new HttpRequestMessage(method, uri);
        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
        if (body != null) {
            request.Content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
        }
        var responseMessage = await httpClient.SendAsync(request).ConfigureAwait(false);
        responseMessage.EnsureSuccessStatusCode();
        response = await responseMessage.Content.ReadAsAsync<T>();
    }
    return response;
}

private async Task<string> AcquireTokenAsyncForApplication() {
    ClientCredential clientCred = new ClientCredential(appId, appKey);
    var authenticationContext = new AuthenticationContext(authority, false);
    AuthenticationResult authenticationResult = authenticationContext.AcquireToken(graphUrl, clientCred);
    return authenticationResult.AccessToken;
}

private Uri getServicePointUri() {
    Uri servicePointUri = new Uri(graphUrl);
    Uri serviceRoot = new Uri(servicePointUri, tenantId);
    return serviceRoot;
}

這篇關(guān)于如何使用 Azure Active Directory .NET SDK 刪除 AppRoleAssignment?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進(jìn)行身份驗(yàn)證并跨請(qǐng)求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權(quán)不起作用)
ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登錄使用角色)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問(wèn)令牌和刷新令牌) - IT屋-程序員軟件開(kāi)發(fā)技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問(wèn)令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時(shí) Azure KeyVault Active Directory AcquireTokenAsync 超時(shí))
主站蜘蛛池模板: 五月婷婷色 | 婷婷色国产偷v国产偷v小说 | 日韩在线看片 | www网站在线观看 | 国产精品69av | 国产精品久久一区 | 精品国产伦一区二区三区观看说明 | 男人天堂网址 | 日本高清不卡视频 | 天天干天天玩天天操 | 亚洲综合婷婷 | 欧美精品在线播放 | 中文字幕一区二区三区日韩精品 | 一区二区国产精品 | 欧美成年黄网站色视频 | 美女天天干天天操 | 欧美a级成人淫片免费看 | 黄视频国产| 国产精品大片 | 一区二区高清不卡 | 91传媒在线观看 | 国产精品一区三区 | 久一久| 影视一区 | 免费观看一级毛片 | 在线色 | 国产精品1区2区 | 日本不卡免费新一二三区 | 日本在线观看视频 | 久久精品国产99国产 | 久久久久免费精品国产 | 二区在线观看 | 国产亚洲精品久久久久久牛牛 | 中文字幕一区二区三区在线观看 | av在线播放不卡 | 国产成人精品一区二区三区网站观看 | 久久久久无码国产精品一区 | 风间由美一区二区三区在线观看 | 精品一级电影 | 久久国产精品一区二区三区 | 亚洲欧美在线观看视频 |