web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Issues authenticating CRM user using logged in user credentials

(0) ShareShare
ReportReport
Posted on by

I am trying to develop a C# WPF application that will update records in CRM. I want the application to automatically authenticate based on the currently logged in users domain credentials.

I have read a few tutorials that provide the following code:

Uri prodOrgUri = new Uri("https://crm.domain.com:<port>/<org>/XRMServices/2011/Organization.svc");
Uri homeRealmUri = null;

ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

using (OrganizationServiceProxy _Service = new OrganizationServiceProxy(prodOrgUri, homeRealmUri, credentials, null))
{
    _Service.EnableProxyTypes();
    IOrganizationService _iOrganizationService = (IOrganizationService)_Service;
    var context = new XrmServiceContext(_iOrganizationService);

    // CRM code
}

However this always fails to authenticate. I have no problem connecting via this method when I manually define the login credentials, it is only when trying to automatically authenticate the user.

Debugging the code shows that the ClientCredential object has blank values for domain, username and password.

Any help in this matter would be much appreciated. Not having the user typing in their login credentials is an integral part of this application.

Thanks in advance,

Daniel Di Giandomenico


*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    You can try System.Security.Principal.WindowsIdentity.GetCurrent().User to get current logged in details

  • Community Member Profile Picture
    on at

    Using System.Security.Principal.WindowsIdentity.GetCurrent() successfully returned information about the currently logged in user.

    However the OrganizationServiceProxy only accepts a ClientCredentials object. How can I use the WindowsIdentity to authenticate with CRM?

  • Suggested answer
    Jitendra Sahu Profile Picture
    2 on at

    Hi Daniel,

    If you are working on WPF then you can go for on demand authentication, where you can ask logged in user to enter his credentials.

  • Community Member Profile Picture
    on at

    Hi Jitenda,

    One of the feature requests for this application was that the user would not have to enter their credentials.

    Does your response imply that this is not available when working within WPF and my only option is to use on demand authentication?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans