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)

Console app to use running user's credentials?

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

  • awalters Profile Picture
    3,079 on at

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

  • Community Member Profile Picture
    on at

    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
    3,079 on at

    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.

  • awalters Profile Picture
    3,079 on at

    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.

  • Community Member Profile Picture
    on at

    Hi Allison,

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

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

  • awalters Profile Picture
    3,079 on at

    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!

  • Panky Profile Picture
    155 on at

    Hi Allison,

    Did you find any solution for the same ?

  • awalters Profile Picture
    3,079 on at

    Nothing more than the workarounds above, unfortunately.

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