Friday, May 25, 2018

AggregateException was unhandled while connect to Dynamics 365 using OAuth

Recently  I was trying to connect to Dynamics 365 (v9.0) using OAuth, but was facing AggregateException


upon looking at the details of the exception I see its related to security




Once I placed below code, it started working fine

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

By the way here is the sample coe

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            var execute = Task.Run(async () => await Auth());
            Task.WaitAll(execute);

        }

        public static async Task Auth() {

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            var ap = await AuthenticationParameters.CreateFromResourceUrlAsync(
              new Uri("https://<<org>>.api.crm.dynamics.com/api/data/v9.0"));

            String authorityUrl = ap.Authority;
            String resourceUrl = ap.Resource;

            var authContext = new AuthenticationContext(authorityUrl);
            var clientCred = new ClientCredential("ApplicationID", "Key");
            var test = await authContext.AcquireTokenAsync(resourceUrl, clientCred);

            Console.WriteLine(test.AccessToken);

            using (var client = new HttpClient()) {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", test.AccessToken);

                var response = await client.GetAsync("https://<<org>>.api.crm.dynamics.com/api/data/v9.0/contacts");
                var contacts = await response.Content.ReadAsStringAsync();

                Console.WriteLine(contacts);
            }
        }
        }
    }

Monday, April 24, 2017

Access Teams

With owner teams or access teams, you can easily share business objects and collaborate with the users across business units in Microsoft Dynamics 365. A team belongs to one business unit, but it can include users from other business units. A user can be associated with more than one team.
An owner team owns records and has security roles assigned to the team. The team’s privileges are defined by these security roles. In addition to privileges provided by the team, team members have the privileges defined by their individual security roles and by the roles from other teams in which they are members. A team has full access rights on the records that the team owns.

AggregateException was unhandled while connect to Dynamics 365 using OAuth

Recently  I was trying to connect to Dynamics 365 (v9.0) using OAuth, but was facing AggregateException upon looking at the details ...