Advertisements

About Debajit
I am a Dynamics CRM Most Valuable Professional (MVP) with 10 years of experience in Microsoft .NET Technologies and 7 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

12 Responses to {Dynamics CRM+ Authentication}–Authentication with Dynamics CRM online Web API without user login screen– Where headless authentication works and where not?

  1. Hi Debajit,
    Tried couple of ways to test the console app, but getting authentication issues.

    opt1 – authorityUri=https://login.microsoftonline.com/jksoft123.crm4.dynamics.com/oauth2/authorize

    UserCredential userCredential = new UserCredential(“”, “”);
    string authorityUri = “https://login.microsoftonline.com/jksoft123.crm4.dynamics.com/oauth2/authorize”;
    TokenCache tokenCache = new TokenCache();
    AuthenticationContext context = new AuthenticationContext(authorityUri);
    AuthenticationResult result = context.AcquireToken(“https://jksoft123.crm4.dynamics.com”, “f3aaf9d8-baca-4f0d-a88d-1fa6e1ce694f”, userCredential);
    LoadAccounts(result.AccessToken);

    Error

    ‘authority’ is not in the list of valid addresses. unknown_error (login.microsoftonline.com):
    Access Denied

    Access Denied (authentication_failed)

    Your credentials could not be authenticated: “Credentials are missing.”. You will not be permitted access until your credentials can be verified.

    This is typically caused by an incorrect username and/or password, but could also be caused by network problems.

    For assistance, contact your network support team.

    opt2 –
    authorityUri=”https://login.windows.net/jksoft123.onmicrosoft.com/oauth2/authorize”;

    UserCredential userCredential = new UserCredential(“”, “”);
    string authorityUri = “https://login.windows.net/jksoft123.onmicrosoft.com/oauth2/authorize”;
    TokenCache tokenCache = new TokenCache();
    AuthenticationContext context = new AuthenticationContext(authorityUri);
    AuthenticationResult result = context.AcquireToken(“https://jksoft123.crm4.dynamics.com”, “f3aaf9d8-baca-4f0d-a88d-1fa6e1ce694f”, userCredential);
    LoadAccounts(result.AccessToken);

    Error

    user_realm_discovery_failed: User realm discovery failed
    {“The remote server returned an error: (407) Proxy Authentication Required.”}

    • Debajit says:

      Hi,

      Just confirming, prior to running this code, did you do the following steps
      1. add your Dynamics Online directory to Azure
      2. When you registered your application with Dynamics Online AD, did you allow implicit authorization. Also I assume you tried this from a native client like Console or WPF
      3. Did you provide access to the Dynamics CRM online instance for your app?

      In case you have missed any of the above, complete that and try with option2 again. It should work. If not, let me know.

      Regards
      Debajit

      • I have gone through your first post and it works fine for the web client. But for the Console app, i am getting the above errors, yes, points 1,2,3 are all completed.

  2. Hi Debajit, Thank you for your efforts in maintaining this tutorial. I am learning Dynamic CRM and trying to get the access token of the current session when user actively using online CRM instance. Every api talks only about taking token using url and callback. Can you guide me in right direction ?

  3. Christopher says:

    How do I do the opposite? I want CRM to manage sigin activities, not my app.

  4. Pankaj vats says:

    Hi Debajit
    Please help me out !!!
    1. I have Rest Api and its hosted on our Server
    2. I want to Integrate my Rest Api with Dynamic CRM 365.

    Scenario:-
    Suppose when user create any Accounts/Contacts in Dynamic CRM 365 and fill some value in Postal-Code/Zip-Code and click on Save Button.
    On Click of save button , validate this Postal-code through Rest Api which is hosted on other server and API send respose to the Dynamic CRM 365 which is valid Postal code or not

  5. Chamali says:

    Hi Debajit..Thanks for this tutorial which saved me a lot of time. I too was trying access CRM web APIs in a web application and had no luck to find an overload method which uses both client id and client secret (which is really needed for a web application) What I finally did was to self host WCF services in a console application and register it as a native app in AAD. It worked great!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: