繁体   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