2017-05-14 1 views
1

아이디어는 Azure Powershell처럼 작동하도록 만드는 것입니다. 즉, 표준 Active Directory 인증 대화 상자가 나타나고, 내 자격 증명을 입력하고, AzureAD가 수행 한 다음 콘솔 응용 프로그램이 특정 웹 서비스에 액세스 할 수 없습니다.콘솔 응용 프로그램에서 AzureAD 인증을 사용할 수 있습니까?

이것이 가능합니까? 그렇게 열심히해서는 안되지만 예제를 찾을 수 없습니다.

WPF 예제를 보면 app.config에 클라이언트 ID가 설정되어있는 것을 볼 수 있습니다. 이게 정말 필요한가요? 내 말은, 단일 페이지 js 앱이 광고에 등록되어 있지 않습니까?

+0

단일 페이지 JS 응용 프로그램은 AD 인증 – Justin

+1

https://github.com/Azure-Samples/active-directory-dotnet-graphapi-를 사용하는 AD에 등록 될 필요가있다 콘솔? – 4c74356b41

+0

콘솔 응용 프로그램이 Azure AD에서 보호하는 웹 API에 액세스하는 샘플 - https://blogs.msdn.microsoft.com/benjaminperkins/2016/10/20/how-i-connected-a-console-application-to- a-web-api-protected-by-a-azure-active-directory / – alwayslearning

답변

0

사실 모든 클라이언트 응용 프로그램은 AAD에 등록해야합니다.

콘솔 앱도 Azure AD에 등록되어 있어야하므로 클라이언트 ID 및 클라이언트 리디렉션 URL은 있지만 클라이언트 비밀은 유지되지 않습니다. 그런 다음, 다음 코드는 작동합니다 :

void Main() 
{ 
    var clientId = "client-GUID"; 
    var clientUrl = new Uri("redirect-url"); //can be anything starting with localhost 
    var tenant = "name of your AAD tenant"; 
    string authority = "https://login.windows.net/" + tenant; 

    string resource = "https://outlook.office365.com"; ///put id or url of resource you're accessing 

    AuthenticationContext authenticationContext = new AuthenticationContext(authority, false); 

    Console.WriteLine("Trying to acquire token"); 

    var pp = new PlatformParameters(PromptBehavior.Auto); //this brings web prompt 
    var token = authenticationContext.AcquireTokenAsync(resource, clientId, clientUrl, pp, UserIdentifier.AnyUser).Result; 
    Console.WriteLine("Got the token: {0}", token.AccessToken); 
} 
관련 문제