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

Azure AD AcquireToken 不適用于應(yīng)用密碼

Azure AD AcquireToken does not work with app password(Azure AD AcquireToken 不適用于應(yīng)用密碼)
本文介紹了Azure AD AcquireToken 不適用于應(yīng)用密碼的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試使用 .NET ADAL 庫驗證 Azure AD 中的用戶密碼.這適用于沒有 MFA 的普通用戶帳戶,但我遇到了為已激活 MFA 的用戶執(zhí)行此操作的問題.

I'm trying to verify a user's password in Azure AD using the .NET ADAL library. This works fine for a regular user account without MFA, but I ran into problems doing this for a user who has MFA activated.

當(dāng)使用用戶的實際密碼時,我得到了 AADSTS50076: Application password is required.,這很公平,但是當(dāng)我創(chuàng)建一個新的應(yīng)用程序密碼時,我收到了錯誤 AADSTS70002: 驗證憑據(jù)時出錯.AADSTS50020:用戶名或密碼無效.我已經(jīng)創(chuàng)建了多個應(yīng)用密碼,但它們都不起作用.

When using the user's actual password, I got AADSTS50076: Application password is required., which is fair enough, but when I then created a new app password, I received the error AADSTS70002: Error validating credentials. AADSTS50020: Invalid username or password. I've created multiple app passwords but they all do not work.

用于嘗試驗證的代碼如下:

The code used to attempt authentication is as follows:

var ac = new AuthenticationContext("https://login.windows.net/my-tenant.com");
var authResult = ac.AcquireToken("https://graph.windows.net", "my-client-id", new UserCredential("my.account@my-tenant.com", "my-password"));

嘗試進行身份驗證的用戶是此 AD 中的全局管理員.

The user that is trying to authenticate is a Global Admin in this AD.

是否甚至可以為具有 MFA 的用戶進行這樣的身份驗證?

Is it even possible to do authentication like this for a user with MFA?

推薦答案

所以,為了回答我自己的問題,我采取了以下措施(為簡潔起見):

So, to answer my own question somewhat, I resorted to doing the following (cleaned up for brevity):

public class AzureAdAuthenticationProvider
{
    private const string AppPasswordRequiredErrorCode = "50076";
    private const string AuthorityFormatString = "https://login.windows.net/{0}";
    private const string GraphResource = "https://graph.windows.net";

    private AuthenticationContext _authContext;
    private string _clientId;

    public AzureAdAuthenticationProvider()
    {
        var tenantId = "..."; // Get from configuration

        _authContext = new AuthenticationContext(string.Format(AuthorityFormatString, tenantId));
    }

    public bool Authenticate(string user, string pass)
    {
        try
        {
            _authContext.AcquireToken(GraphResource, _clientId, new UserCredential(user, pass));

            return true;
        }
        catch (AdalServiceException ase)
        {
            return ase.ServiceErrorCodes.All(sec => sec == AppPasswordRequiredErrorCode);
        }
        catch (Exception)
        {
            return false; // Probably needs proper handling
        }
    }
}

它不漂亮,但它可以完成工作.

It's not pretty, but it does the job.

通過使用ServiceErrorCodes.All(),我保證只有當(dāng)一個AppPasswordRequired錯誤發(fā)生時,認證成功.

By using ServiceErrorCodes.All(), I ensure that only when a single AppPasswordRequired error occurs, authentication has succeeded.

此方法的唯一缺點是啟用 MFA 的用戶必須使用其實際帳戶密碼才能登錄.似乎不支持使用應(yīng)用密碼.

The only disadvantage to this method, is that a user with MFA enabled has to use their actual account password to login. Using an app password does not seem to be supported.

這篇關(guān)于Azure AD AcquireToken 不適用于應(yīng)用密碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

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 令牌授權(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(如何獲取守護進程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發(fā)技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
主站蜘蛛池模板: 日韩中文字幕av | 在线播放国产一区二区三区 | 欧洲毛片 | 国产精品视频导航 | 视频一区二区三区中文字幕 | 日本在线免费视频 | 女朋友的闺蜜3韩国三级 | 五月综合激情婷婷 | 一级全黄少妇性色生活免费看 | 欧美日韩综合一区 | 亚洲 中文 欧美 日韩 在线观看 | 成人a视频在线观看 | 韩日一区二区 | 欧美成人激情 | 色播av| 日韩一区二区三区四区五区六区 | 中文字幕在线三区 | www.日本在线 | 免费一级淫片aaa片毛片a级 | 亚洲国产一区在线 | 亚洲欧美综合精品久久成人 | 人人擦人人 | 国内精品久久久久久影视8 最新黄色在线观看 | www.日本精品 | 狠狠插天天干 | 欧美日韩在线不卡 | 国产中文区二幕区2012 | 久久精品国产一区二区电影 | 人人玩人人添人人澡欧美 | 日韩精品成人网 | 国产蜜臀97一区二区三区 | 国产黄色电影 | 美女久久久久久久 | 毛片a级 | 久久中文字幕一区 | 91精品国产99 | 91精品久久久久久久99 | 国产激情自拍视频 | 性一交一乱一伦视频免费观看 | 久久综合一区 | 国产福利视频 |