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

使用 asp.net Identity 進行 Azure AD 身份驗證以進行授

Azure AD authentication with asp.net Identity for authorisation(使用 asp.net Identity 進行 Azure AD 身份驗證以進行授權)
本文介紹了使用 asp.net Identity 進行 Azure AD 身份驗證以進行授權的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我試圖在整個互聯網上尋找,但看不到如何實現我被要求的目標.這是我的企業應用程序,它使用 Asp.net Identity 進行基于表單的身份驗證.我已經擴展了用戶和角色以及組以在我的代碼中提供授權.(注意:不使用任何組/角色指令).

I tried to look for all over internet but couldn't see how I can achieve what I was asked to. Here is my enterprise app which uses Asp.net Identity for form based authentication. I had extended User and Role along with Groups to provide authorization in my code. (note: not using any group/role directives).

現在我被要求研究更改代碼以適應 Azure Active Directory 身份驗證的可能性.我嘗試閱讀如何注冊應用程序、將用戶發送到 Azure 站點進行身份驗證、取回令牌等.但是我被困在之后怎么辦?"我已通過身份驗證的用戶如何使用我現有的 Asp.net Identity 模型,其中用戶存儲在 sql 數據庫中.如何使用此令牌關聯現有用戶.

Now I was asked to look at possibility of changing code to accommodate Azure Active Directory authentication. I tried reading on how you can register app, send user to Azure site for authentication, get back token etc. However I'm stuck at 'what-afterwards?' I have authenticated user How can I use my existing Asp.net Identity model where user was stored in sql database. How to use this token to relate the existing user.

此外,當我將項目更改為允許 Azure AD 時,它會刪除 Aspnet.Identity 包,因為它與 Azure AD 不兼容!!

Moreover, when I change my project to allow Azure AD, it removes Aspnet.Identity package as its not compatible with Azure AD !!

我什至嘗試手動將兩個包并排放置,我必須指出用戶被發送到 Azure 上進行身份驗證的位置,然后轉回主頁并再次以永無止境的循環登錄 Azure AD.

I even tried manually keeping both packages side by side, I got to point where user is sent to authenticate on Azure, diverted back to home page and again to login on Azure AD in never ending loop.

總結問題,我如何從 AAD 驗證用戶并繼續使用現有的角色和組授權.

to summarize the question, How can I authenticate user from AAD and keep using existing Roles and groups authorization.

我嘗試創建單獨的 Web 服務來驗證用戶并發送 JWT 令牌.如果我直接在瀏覽器上調用它可以找到,但是,當我嘗試從我的網絡應用程序調用此服務時,我得到了奇怪的錯誤

I tried creating separate web service which will authenticate user and send JWT token. which works find if I call it directly on browser, however, when I tried to call this service from my web app I get weird error

 Application with identifier 'a2d2---------------' was not found in the directory azurewebsites.net

這里的奇怪部分是目錄名稱是azurewebsites.net",而不是我使用的默認目錄.

Weird part here is name of directory is 'azurewebsites.net' and not the default directory I'm using.

更新這是引發錯誤的代碼

public async Task<ActionResult> Login(string returnUrl)
        {


            try
            {

                // get the access token
                AuthenticationContext authContext = new AuthenticationContext(authority, new TokenCache());

                var clientCredential = new ClientCredential(clientId, password);
//Error on below line
                AuthenticationResult result = await authContext.AcquireTokenAsync(resourceId, clientCredential);


                // give it to the server to get a JWT
                HttpClient httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
......

推薦答案

試試這個:

var client = new RestClient("https://login.microsoftonline.com/{tenant- 
         Id}/oauth2/v2.0/token");
var request = new RestRequest(Method.POST);         
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");         
request.AddHeader("grant_type", "password");
request.AddParameter("application/x-www-form-urlencoded", 
        "grant_type=password&client_id={client-Id}&client_secret={client- 
        secret}&scope={scopeurl}&userName={username}&password={password}", 
        ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
var json = response.Content;
var JSONObject = JObject.Parse(json);
var token = (string)JSONObject["access_token"];

這篇關于使用 asp.net Identity 進行 Azure AD 身份驗證以進行授權的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 精久久 | 欧美精品一区二区在线观看 | 啪啪免费网站 | 欧美一区二区在线 | 国产精品毛片一区二区三区 | 国产不卡一区在线观看 | 亚洲精品字幕 | www.99re| 成人一级毛片 | 日韩中文久久 | 国产福利视频在线观看 | 欧美一区二区三区在线免费观看 | 国产亚洲精品美女久久久久久久久久 | 亚洲高清视频在线观看 | 新91视频网| 中文字幕视频一区二区 | 精品久久久久久久久久久久久久久久久 | 久久99精品久久 | 久久av一区二区三区 | 日本成人免费网站 | 日韩在线小视频 | 国产欧美一区二区三区另类精品 | 久久久久久国产 | 久操国产 | 国产一级视屏 | 日韩欧美黄色 | 国产福利91精品一区二区三区 | 久久久免费 | 精品中文字幕在线 | 亚洲精品一区二区三区在线 | 精品国产乱码久久久久久蜜柚 | 欧美激情欧美激情在线五月 | 91深夜福利视频 | 精品九九久久 | 一区二区精品视频 | 欧美日韩高清一区 | 成人免费视频在线观看 | 久久亚洲91 | 欧美a区 | 久久福利网站 | 日韩成人免费视频 |