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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

no prompt logon to crm through adfs

(0) ShareShare
ReportReport
Posted on by 5

Sorry if this has already been answered but I have googled and BINGed for days and not found a way to do this.

We recently upgraded to CRM 2016. As a part of this, I rewrote a good many automated processes, (many are run as windows services), some run in an external internet facing application. This all went well. Now we need to implement outlook integration, which requires us to use ADFS for single signon. However, I have not been able to find a way to authenticate without a ui prompting for credentials. This means that my windows services won't work because of the login prompt. I really need to pass the credientials programatically. Is this possible? If not, I am faced with having to rewrite all the integration code to use IOrganizationService and move away from the simple rest interface which is already fully tested and very stable.

The error I get when trying to pass credetials is:

The authorization server does not support the requested 'grant_type': 'password'.

Here is the code I am working with:

 class clsTest
    {
        private static WebClient client;
        private static string authorityURL = "sts.somedomain.com/.../authorize";
        private static string resource = "https://crm.somedomain.com/";
        private static string redirectUrl = "externalapp.somedomain.com";
        private static string clientID = "some-unique-id-registred-in-adfs";


        static void Main(string[] args)
        {
            authorize("domain\\userid", "password"); //GENERATES EXCEPTION

            authorizeWithUI(); //WORKS BUT PROMPTS FOR LOGIN
        }

        private static void authorize(string user, string password)
        {
            UserCredential cred = new UserCredential(user, password);
            AuthenticationContext _authenticationContext = new AuthenticationContext(authorityURL, false);
            AuthenticationResult result = _authenticationContext.AcquireTokenAsync(resource, clientID, cred).Result;
            string rtn = new AuthenticationHeaderValue("Bearer", result.AccessToken).ToString();
        }

        private static void authorizeWithUI()
        {
            AuthenticationContext authContext = new AuthenticationContext(authorityURL, false);
            AuthenticationResult result = authContext.AcquireToken(resource, clientID, new Uri(redirectUrl));
            AuthenticationHeaderValue ahv = new AuthenticationHeaderValue("Bearer", result.AccessToken);
            WebClient client = getNewHttpClient(resource);
            client.Headers[HttpRequestHeader.Authorization] = ahv.ToString();
            client.Headers[HttpRequestHeader.ContentType] = "application/json";
            client.Headers[HttpRequestHeader.Accept] = "application/json";
            string json = client.DownloadString(resource + "stringmaps?$filter=attributename eq ('new_plstrainer') and objecttypecode eq 'opportunity'");
            string rtn = ahv.ToString();
        }

        private static WebClient getNewHttpClient(string webAPIBaseAddress = "crm.somedomain.com/.../v8.2")
        {
            client = new WebClient();
            client.Headers[HttpRequestHeader.ContentType] = "application/json";
            client.Headers[HttpRequestHeader.Accept] = "application/json";
            client.BaseAddress = webAPIBaseAddress;
            return client;
        }
    }


Thanks

Randy S.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hi Randy,

    I think this was an ADFS limitation, and should be working with ADFS 3.0 (Windows Server 2016?)

    What ADFS are you on?

    Regards,

    Radu

  • Randy Stinson Profile Picture
    5 on at

    It would be server 2012 r2, so ADFS 2.0 I think.

  • Randy Stinson Profile Picture
    5 on at

    Thanks for the quick response!

    Would upgrading to server 2016 help? If so, I am sure it can't be that simple..

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hi Randy,

    Here is the article describing the supported authorization grant types for adfs on ws 2012 r2 blogs.technet.microsoft.com/.../oauth-2-0-support-in-adfs-on-windows-server-2012-r2

    Unfortunately i can't find the blog article where this is described as being supported with ADFS 3.0 - from what i recall upgrading to 3.0 did the trick but i am not 100% sure.

    Can you test your code against a crm online organization? That might help confirm

  • Randy Stinson Profile Picture
    5 on at

    We are going to upgrade our sandbox to server 2016.

  • Radu Chiribelea Profile Picture
    6,667 on at

    Cool - please let me know if this solves the problem.

    Good luck!

  • Randy Stinson Profile Picture
    5 on at

    Could not get it to work. One thing I forgot to mention is that the main client in question is outside the domain. After more digging trying to get it to work, I found this post: blogs.technet.microsoft.com/.../oauth-2-0-confidential-clients-and-active-directory-federation-services-on-windows-server-2016, which states "When your client runs on a domain-joined machine, you can use the Windows Integrated Authentication". So...

    Could a different authentication service be used? IdentityServer or CAS? CAS already has a LDAP module, that we are using this for some non .net apps, so might it be possible to get a security token from one of these and pass it to CRM? Has anyone tried this?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans