[英]sample code for Microsoft Dynamics 365 CRM authentication and then redirect to C# console application
I want to C# console application code for Microsoft authentication, and when I click button redirect to Microsoft login page and after authentication redirect to C# application.我想要 C# 控制台应用程序代码进行 Microsoft 身份验证,当我单击按钮重定向到 Microsoft 登录页面并在身份验证后重定向到 C# 应用程序。 Thanks in Advance提前致谢
I'd suggest installing D365DeveloperExtensions for Visual Studio.我建议为 Visual Studio 安装D365DeveloperExtensions 。 This will give you a pre-built template for creating a console application that connects to a Dynamics 365 environment.这将为您提供一个用于创建连接到 Dynamics 365 环境的控制台应用程序的预构建模板。
Alternatively below is sample code for login options with either a credential prompt (Microsoft login page) or without.或者,下面是带有或不带有凭据提示(Microsoft 登录页面)的登录选项的示例代码。 Code taken fromthis blog .取自此博客的代码。
//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.