DefaultAzureCredential 문제 해결: 사용되는 자격 증명 식별

발행: (2025년 12월 10일 오후 11:09 GMT+9)
2 min read
원문: Dev.to

Source: Dev.to

문제

Azure Identity NuGet 패키지를 사용할 때 DefaultAzureCredential은 환경 변수, Visual Studio, Azure Managed Identity 등 다양한 인증 유형을 로드하려고 시도합니다. 전체 목록은 Azure 문서에 정리되어 있습니다.

https://learn.microsoft.com/en-us/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet

어떤 인증이 실제로 사용되는지 파악하려면 로그를 수동으로 활성화해야 하므로 어려울 수 있습니다. Microsoft에서 권장하는 방법은 매우 상세한 출력을 제공합니다. 출력을 간소화하려면 아래 코드를 애플리케이션 시작 부분에 삽입하세요.

using var listener = new AzureEventSourceListener((e, message) =>
{
    if (e.EventSource.Name == "Azure-Identity")
    {
        Console.WriteLine(message);
        // Alternatively, use _logger.LogInformation() if running in Azure
        // WARNING: These logs may include sensitive credentials
        // depending on the options selected below
    }
},
System.Diagnostics.Tracing.EventLevel.LogAlways);

DefaultAzureCredentialOptions options = new DefaultAzureCredentialOptions
{
    Diagnostics =
    {
        IsAccountIdentifierLoggingEnabled = true,
        // Useful extra options for debugging
        // These act as a whitelist of fields to log.
        // LoggedHeaderNames = { "x-ms-request-id" },
        // LoggedQueryParameters = { "api-version" },
        // This enables logging the request or response body
        // IsLoggingContentEnabled = true
    }
};

AzureEventSourceListener는 상세 로거를 생성합니다. 위와 같이 필터를 추가하면 많은 잡음이 제거됩니다.

비슷한 출력이 표시됩니다:

EnvironmentCredential.GetToken invoked
EnvironmentCredential.GetToken was unable to retrieve an access token
...
VisualStudioCredential.GetToken succeeded

이 출력 덕분에 어떤 인증 유형이 성공했는지(또는 실패했는지)를 쉽게 식별할 수 있습니다.

Azure Identity 로깅

https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md#logging

관련 이슈

https://github.com/Azure/azure-sdk-for-net/issues/27872

Back to Blog

관련 글

더 보기 »

C#에서 Excel 셀 병합 방법

필수 조건 시작하기 전에 다음이 설치되어 있는지 확인하십시오: - 머신에 Visual Studio가 설치되어 있음. - Spire.XLS가 설치되어 있음. 다운로드는 ...에서 할 수 있습니다.