简体   繁体   English

Microsoft Dynamics 365 CRM 身份验证的示例代码,然后重定向到 C# 控制台应用程序

[英]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.

相关问题 使用 C# 代码从 DYNAMICS 365 crm 检索/获取记录 - Retrieve/fetch records from DYNAMICS 365 crm using C# code 从.Net访问Microsoft CRM Dynamics 365 - Access to Microsoft CRM Dynamics 365 from .Net 如何通过使用C#代码在Microsoft Dynamics 365中附加注释中的图像(注) - How to attach Image in Annotation(Note) in Microsoft Dynamics 365 By using C# code 通过代码(C#)使用Microsoft Dynamics CRM 2011(IFD)对用户进行身份验证 - Authenticate users with Microsoft Dynamics CRM 2011 (IFD) through code (C#) 使用代码对Microsoft Dynamics CRM进行身份验证 - Authenticating Microsoft Dynamics CRM with Code Dynamics 365 (CRM) 9.1 版在线 C# 代码错误:实体 ID 必须与属性包中设置的值相同 - Dynamics 365 (CRM) Version 9.1 online C# code Error: Entity Id must be the same as the value set in property bag Microsoft Dynamics CRM C#插件以使用Jquery和Ajax - Microsoft Dynamics CRM C# Plugin to use Jquery and Ajax 使用C#连接到Windows Form Application中的Dynamics CRM - Connect to Dynamics CRM in Windows Form Application using C# 在 Microsoft Dynamics 365 CRM 中导入解决方案时在实体上注册插件 - Register a Plugin on a Entity when a Solution is imported in Microsoft Dynamics 365 CRM Dynamics 365 CRM 集成 - Dynamics 365 CRM integration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM