簡體   English   中英

Microsoft Dynamics 365 CRM 身份驗證的示例代碼,然后重定向到 C# 控制台應用程序

[英]sample code for Microsoft Dynamics 365 CRM authentication and then redirect to C# console application

我想要 C# 控制台應用程序代碼進行 Microsoft 身份驗證,當我單擊按鈕重定向到 Microsoft 登錄頁面並在身份驗證后重定向到 C# 應用程序。 提前致謝

我建議為 Visual Studio 安裝D365DeveloperExtensions 這將為您提供一個用於創建連接到 Dynamics 365 環境的控制台應用程序的預構建模板。

或者,下面是帶有或不帶有憑據提示(Microsoft 登錄頁面)的登錄選項的示例代碼。 取自此博客的代碼。

//Azure Application Client ID
private const string _clientId = "00000000-0000-0000-0000-000000000000";
// Azure Application REPLY URL - can be anything here but it must be registered ahead of time
private const string _redirectUrl = "http://localhost/CrmWebApi";
//CRM URL
private const string _serviceUrl = "https://org.crm.dynamics.com";
//O365 credentials for authentication w/o login prompt
private const string _username = "administrator@org.onmicrosoft.com";
private const string _password = "password";
//Azure Directory OAUTH 2.0 AUTHORIZATION ENDPOINT
private const string _authority = 
 "https://login.microsoftonline.com/00000000-0000-0000-0000-000000000000";
private static AuthenticationResult _authResult;
AuthenticationContext authContext =
    new AuthenticationContext(_authority, false);
//Prompt for credentials
//_authResult = authContext.AcquireToken(
//    _serviceUrl, _clientId, new Uri(_redirectUrl));

//No prompt for credentials
UserCredential credentials = new UserCredential(_username, _password);
_authResult = authContext.AcquireToken(
    _serviceUrl, _clientId, credentials);

var token = _authResult.AccessToken;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM