Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Office365 authentication type and OrganizationServiceProxy class for connecting to Common Data Service Deprecated

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello,

I am using "organizationServiceManager" to connect to CDS and "ManagedTokenOrganizationServiceProxy" to get the proxy, i am afraid that "ManagedTokenOrganizationServiceProxy" will be deprecated because it is derived from OrganizationServiceProxy as shown in the code below, So can someone confirme that the class is going to be deprecated and how i can fix my code.

 

var organizationServiceManager = new OrganizationServiceManager(url, login, password)

ManagedTokenOrganizationServiceProxy GetProxy =  organizationServiceManager.GetProxy();

namespace Microsoft.Pfe.Xrm
{
  public sealed class ManagedTokenOrganizationServiceProxy : OrganizationServiceProxy
  {
    public ManagedTokenOrganizationServiceProxy(IServiceManagement<IOrganizationService> serviceManagement, ClientCredentials credentials);
    public ManagedTokenOrganizationServiceProxy(IServiceManagement<IOrganizationService> serviceManagement, SecurityTokenResponse securityTokenResponse, ClientCredentials credentials);

    protected override void AuthenticateCore();
    protected override void ValidateAuthentication();
  }
}

  • cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Office365 authentication type and OrganizationServiceProxy class for connecting to Common Data Service Deprecated

    Hi Mitmog4Ever,

    I also found some community answers which mentioned that CrmServiceClient handles token renewal automatically, and they might be links what you had reviewed.

    https://stackoverflow.com/questions/57757830/sometime-iorganizationservice-object-is-null

    https://community.dynamics.com/365/f/dynamics-365-general-forum/315831/renew-token-organizationserviceproxy/931240

    It seems that there is no clear official statement(like documentation) available on Internet yet that how does exactly CrmServiceClient handle token renewal, but migrating to CrmServiceClient would be the right direction.

    (You could open a discussion on GitHub page of CrmServiceClient to ask for technical details of the class, only you might be told to back to forum again. :) )

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Office365 authentication type and OrganizationServiceProxy class for connecting to Common Data Service Deprecated

    Hello Clofly Mao,

    Thank you so much for your detailled answer, it was very helpful, i applied everthing u said, and i am going to test it, but i want to know another thing, with OrganisationServiceProxy i was handling the token renewal manually using the code below:

               SecurityTokenExpires = organisationserviceproxy.SecurityTokenResponse.Response.Lifetime.Expires;

               SecurityTokenExpires = SecurityTokenExpires?.AddHours(-4);

    now with CrmServiceClient, i can't find a substitute of the classe SecurityTokenResponse, so searched and i found that CrmServiceClient handels automtically the renewal of the token, according to your experience is that correct, if not can you suggest me a way to fix that issue?, thank you in advance.

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Office365 authentication type and OrganizationServiceProxy class for connecting to Common Data Service Deprecated

    Hi Partner,

    Actually the real thing that is going to be deprecated is WS-Trust authentication, this change impacts custom client applications that use “Office365” authentication and the "OrganizationServiceProxy" or "CrmServiceClient" classes.

    We can follow this guide to fix our current code:

    https://docs.microsoft.com/en-us/powerapps/developer/data-platform/authenticate-office365-deprecation#what-should-i-do-to-fix-my-application-code-if-affected

    "

    If your code uses an Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy instance:

    If you are passing the OrganizationServiceProxy instance around to various methods, or returning the instance from a function, replace all occurrences of the type OrganizationServiceProxy with the IOrganizationService interface. This interface exposes all the core methods used to communicate with Dataverse.

    When invoking the constructor, it is recommend you add the NuGet package Microsoft.CrmSdk.XrmTooling.CoreAssembly to your project and replace all use of OrganizationServiceProxy class constructors with CrmServiceClient class constructors. You will need to alter your coding pattern here, however, for simplicity CrmServiceClient supports connection strings in addition to complex constructors and the ability to provide external authentication handlers. CrmServiceClient implements IOrganizationService, therefore your new authentication code will be portable to the rest of your application code.

    "

    It seems that "OrganizationServiceManager" class is from a GitHub library called "XrmCoreLibrary", I tested the library with its latest version 9.0.7.

    https://www.nuget.org/packages/Pfe.Microsoft.Xrm.CoreV9/

    As its release notes said, the library 

    *  depends on CrmServiceClient using oAuth/Modern Authentication

    * Removed old constructors relying on organizationserviceproxy - we now 100% rely on CrmServiceClient

    So I believe the first action you can take is to update your current Pfe.Xrm package version, and replace ManagedTokenOrganizationServiceProxy with CrmServiceClient class, then get organization service from crmserviceclient.

    Here is my code and it runs successfully.

    2630.JPG

    Uri myUri = new Uri("https://org.api.crm5.dynamics.com/XRMServices/2011/Organization.svc", UriKind.Absolute);
    
    var organizationServiceManager = new OrganizationServiceManager(myUri, "admin@CRM123456.onmicrosoft.com", "123456");
    
    CrmServiceClient crmSvc = organizationServiceManager.GetProxy();
    
    if (crmSvc.IsReady)
    {
        IOrganizationService orgService;
        orgService = (IOrganizationService)crmSvc.OrganizationWebProxyClient != null ? (IOrganizationService)crmSvc.OrganizationWebProxyClient : (IOrganizationService)crmSvc.OrganizationServiceProxy;
        Guid userID = ((WhoAmIResponse)orgService.Execute(new WhoAmIRequest())).UserId;
    
    
        if (userID != Guid.Empty)
        {
            Console.WriteLine("Connection successful"   "Your GUID is: "   userID);
        }
        // retrieveContact(orgService);
    }

    2330.JPG

    As far as I know, with latest authentication method, an Azure Active Directory app is required to be registered to connect to our Dynamics, however, with the latest OrganizationServiceManager class, I connected to my Dynamics without app id successfully, only username and password are used.

    By opening the class, I found that it provides 3 ways for connection.

    pastedimage1615449754150v1.png

    I think the third way would be the recommended way(AAD app id as parameter), but I am curious about how is the second way achieved due to only username and password are passed as parameters.

    You could contact the package owner for technical details.(in NuGet page)

    In a word, what you can do are:

    1. Update current Microsoft.Pfe.Xrm version.

    2. Replace OrganizationServiceProxy with CrmServiceClient.

    3. Contact the package owner to confirm that whether the second method will continue to be supported.

    4. Register an AAD app for modern authentication with the third way.

    https://docs.microsoft.com/en-us/powerapps/developer/data-platform/walkthrough-register-app-azure-active-directory

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans