久久久久久久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)用密碼的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

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

我正在嘗試使用 .NET ADAL 庫驗(yàn)證 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)使用用戶的實(shí)際密碼時(shí),我得到了 AADSTS50076: Application password is required.,這很公平,但是當(dāng)我創(chuàng)建一個(gè)新的應(yīng)用程序密碼時(shí),我收到了錯(cuò)誤 AADSTS70002: 驗(yàn)證憑據(jù)時(shí)出錯(cuò).AADSTS50020:用戶名或密碼無效.我已經(jīng)創(chuàng)建了多個(gè)應(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.

用于嘗試驗(yàn)證的代碼如下:

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"));

嘗試進(jìn)行身份驗(yàn)證的用戶是此 AD 中的全局管理員.

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

是否甚至可以為具有 MFA 的用戶進(jìn)行這樣的身份驗(yàn)證?

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)一個(gè)AppPasswordRequired錯(cuò)誤發(fā)生時(shí),認(rèn)證成功.

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

此方法的唯一缺點(diǎn)是啟用 MFA 的用戶必須使用其實(shí)際帳戶密碼才能登錄.似乎不支持使用應(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)用密碼的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(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 訪問令牌和刷新令牌) - 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)用時(shí) Azure KeyVault Active Directory AcquireTokenAsync 超時(shí))
主站蜘蛛池模板: 亚洲一区二区精品视频 | 精品久久久久久久久久久 | 95国产精品 | 中文字幕在线观看视频一区 | 欧美另类日韩 | 天天操天天插 | 久久综合一区 | 欧美国产视频 | 欧美日韩亚洲视频 | 欧美啊v在线观看 | 日韩国产在线观看 | 在线看片国产精品 | 成人国产精品久久久 | 欧美天堂在线观看 | 成人国产精品久久久 | 爱草在线| 亚洲成人免费视频 | 欧美一级做性受免费大片免费 | a爱视频 | 国产一区二区精品 | 欧美一级黄带 | 国产成人精品一区二区三区四区 | 99精品国自产在线 | 99re6在线视频精品免费 | 国产精品自拍av | 国产激情综合五月久久 | 天天色天天| 中文字幕日本一区二区 | 久久久久国产精品一区二区 | 日韩三级一区 | 中文字幕免费 | 国产精品欧美一区二区三区不卡 | 久热精品视频 | 麻豆亚洲 | 色资源在线 | 日本久草视频 | 成人动漫一区二区 | 亚洲精品一区二区网址 | 一二三四在线视频观看社区 | 久久蜜桃av一区二区天堂 | 精品欧美一区二区精品久久久 |