Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Getting organization service with OAuth authentication type

Posted on by 378

Hi,

The following code is used by me to get organizational services. I know the code looks old. I want to change its authentication type from WS-Trust to Office365 now, but I really don't know any easy way to do it. Does anyone know? I don't think it's possible to just turn OrganizationServiceProxy into IOrganizationService.

public static OrganizationServiceProxy GetOrganizationProxy()
{
    Boolean isConfigExist = ReadConfigurations();
    string _serviceApi = string.Empty;
    string _userName = string.Empty;
    string _passWord = string.Empty;
    if (isConfigExist)
    {
        config = configurations[0];
        _serviceApi = config.OrganizationUri.ToString();
        _userName = config.Credentials.UserName.UserName;
        _passWord = config.Credentials.UserName.Password;
    }

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(OnRemoteCertificateValidationCallback);

    Uri endpoint = new Uri(_serviceApi);
    IServiceManagement serviceManagement =
        ServiceConfigurationFactory.CreateManagement(endpoint);

    OrganizationServiceProxy proxy = null;

    AuthenticationCredentials authCredentials = new AuthenticationCredentials();
    authCredentials.ClientCredentials.UserName.UserName = _userName;
    authCredentials.ClientCredentials.UserName.Password = _passWord;
    AuthenticationCredentials orgtokenCredentials = serviceManagement.Authenticate(authCredentials);
    proxy = new ManagedTokenOrganizationServiceProxy(serviceManagement, orgtokenCredentials.SecurityTokenResponse);

    proxy.EnableProxyTypes();
    proxy.Timeout = new TimeSpan(0, 10, 0);

    return proxy;
}

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Getting organization service with OAuth authentication type

    What deployment do you have?

  • Stone Huang Profile Picture
    Stone Huang 378 on at
    RE: Getting organization service with OAuth authentication type

    Do you know that there is an easy way to get organization service like mine that can be changed directly instead of using a connection string?

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Getting organization service with OAuth authentication type

    Hello,

    I would recommend to use CrmServiceClient to connect to CRM - docs.microsoft.com/.../use-connection-strings-xrm-tooling-connect

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans