Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Console app to use running user's credentials?

Posted on by 3,079

We're using Dynamics 365 on-premise (8.2).  I'm trying to create a console app that runs an action in CRM, so we can schedule the action using Windows Task Scheduler.  (I hate trying to mess around with wait conditions and such in CRM itself - never feels clean/manageable to me.)

I've created a test console app using the guide here (thank you!):  http://joegilldotcom.blogspot.ca/2016/09/simple-dynamics-crm-console-application.html

That works fine with the credentials hard coded in.  My connection string looks like this:  "Url=https://<url>/<orgname>;Domain=<domainname>;UserName=<username>;Password=<password>;AuthType=IFD" />

However, how can I use the credentials of the calling user - which will be the credentials entered when scheduling the task - rather than putting them in the app.config?  Note: this app will only be run on-premise in the same domain; however, we do have IFD enabled.

*This post is locked for comments

  • awalters Profile Picture
    awalters 3,079 on at
    RE: Console app to use running user's credentials?

    Nothing more than the workarounds above, unfortunately.

  • Panky Profile Picture
    Panky 155 on at
    RE: Console app to use running user's credentials?

    Hi Allison,

    Did you find any solution for the same ?

  • awalters Profile Picture
    awalters 3,079 on at
    RE: Console app to use running user's credentials?

    Yes - if I have to hard code them, my plan was definitely to encrypt them.  Just for the sake of maintenance, though, as well as potential flexibility, I wanted the ability to just get it from the execution context.  This particular app is going to be used to schedule workflows from Windows Task Scheduler, which has the ability to store the credentials to be used.  I figured this would be easier for people to maintain in future (if the password or account changes, etc...) then having to go into the code, re-deal with the encryption, and so on.  Ah well - the world is not perfect.  :-)  Thanks!

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Console app to use running user's credentials?

    Allison, one more thing that you might consider, is encrypting the credentials in your console application, and reading them from the Console application. We do that all the time in our applications.

    Let me know if you need help in case this is something you think will work.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Console app to use running user's credentials?

    Hi Allison,

    I can understand the frustration. So yes keeping the creds in a config file seems to be the only solution for now.

  • awalters Profile Picture
    awalters 3,079 on at
    RE: Console app to use running user's credentials?

    So, from another forum I was pointed to documentation around using a NetworkCredentials constructor rather than a connection string.  Then the person suggested I could assign CredentialCache.DefaultNetworkCredentials to that constructor.  Seemed promising.  Tried it, and got the very specific exception - "When using IFD Authentication you cannot use Default Network, or Default Credentials, or Null. Create a credential with the users SPLA credentials."

    Which really implies I'm SOL and hard coding is the only way they've allowed for this, which is quite frustrating.  Going to keep poking at a couple more things, but...not looking good.

  • awalters Profile Picture
    awalters 3,079 on at
    RE: Console app to use running user's credentials?

    I don't want to prompt for them or have them as parameters, no.  I want to use the credentials of the user that the exe is running as.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Console app to use running user's credentials?

    Hi Allison,

    If I understood you correctly, do you mean to say you want to pass the user credentials on run time rather than storing them on the app.config file? If that's the case, you might want to check the below link:

    msdn.microsoft.com/.../hh675404.aspx

    Let me know if this helped.

    Thanks,

  • awalters Profile Picture
    awalters 3,079 on at
    RE: Console app to use running user's credentials?

    I tried that AD example, and it wouldn't connect.  Maybe because we have claims on for IFD?

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Console app to use running user's credentials?

    Hi Allison,

    See the below msdn page regarding connecting using connection string.

    msdn.microsoft.com/.../mt608573.aspx

    Under the connection string examples, see Integrated On Premise Authentication.

    This is basically a connection string with no username, password and domain fields.

    You might need to add parameter LoginPrompt=Never

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans