I am facing issue with connecting Dynamics CRM online instance which has additional security enabled with MFA & ADFS on-premise . Office 365 is setup with Single-Sign-On (SSO) . When login from web we are able to login But programmatically using Organization Service we are not able to connect . following errors are encountered :
ID3242: The security token could not be authenticated or authorized.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
OrganizationServiceProxy service = null;
string ServerUrl = "CRM URL";
ClientCredentials creds = new ClientCredentials();
creds.UserName.UserName = username;
creds.UserName.Password = password;
service = new OrganizationServiceProxy(new Uri(ServerUrl), null, creds, null);
service.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
service.Timeout = new TimeSpan(23, 59, 59);
WhoAmIResponse whoAmIResponse = (WhoAmIResponse)service.Execute(new WhoAmIRequest());
Password , we have created APP password from account security page.