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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

How to connect to an organization service without using app id and redirect uri under the office 365 authentication type

(1) ShareShare
ReportReport
Posted on by 455

Hi everyone,

I used the OrganizationServiceProxy class to connect to the organization service, and the authentication type is ws-trust.


But now dynamics officially requires me to change the authentication protocol to office 365, so I have to change my code, but I find that if I use the authentication type of office 365, I seem to have to provide appid and redirect uri in the connection string.

I wonder if there is a way to connect to the organization service using office 365 authentication without providing these two things, and what are appid and redirect uri?  I've never used it in the previous code.

I tried to change the authType in the following sample code from office365 to OAuth, but the code show requires appid and redirect uri.

8422.png

5141.jpg

I have the same question (0)
  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: How to connect to an organization service without using app id and redirect uri under the office 365 authentication type

    Hi Stone,

    As I see on the documentation, we have two options:

    1. Switch over to using an OAuth based connection string.
    2. NuGet package that includes auto redirect support. This library will redirect an authentication type of Office365 to OAuth and use the example AppId and Redirect URI automatically. This capability is planned for the 9.2.x version of the Microsoft.CrmSdk.XrmTooling.CoreAssembly package.

    In the sample code above, I used the second option. No need to use the appId. 

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

    But, we have to wait for version 9.2 !! But keep in mind that the transition will be: 

    • Effective April 2021, we intend to retire this authentication protocol for all new environments.

    • Effective April 2022, the authentication protocol will be retired for all new and existing environments.

  • Stone Huang Profile Picture
    455 on at
    RE: How to connect to an organization service without using app id and redirect uri under the office 365 authentication type

    Hi,

    The method used in the above code is still the ws-trust authentication type as far as I understand it. If you want to use the office365 authentication type, the authtype in the connection string should be OAuth.

    And if we use office365 as an authentication type, as I reported an error in the code before, it will make you have to provide appid and redirect uri.

    I'm also trying to find a way that doesn't need to provide appid and redirect uri, but now it doesn't seem to be.

  • meelamri Profile Picture
    13,216 User Group Leader on at
    RE: How to connect to an organization service without using app id and redirect uri under the office 365 authentication type

    Hi,

    Any news ?

  • meelamri Profile Picture
    13,216 User Group Leader on at
    RE: How to connect to an organization service without using app id and redirect uri under the office 365 authentication type

    Hi Stone, 

    Yes you are right. 

    If your code is using CrmServiceClient with the “Office365” authentication type:

    You have two options for dealing with this: 

    1. Switch over to using an OAuth based connection string.
    2. NuGet package that includes auto redirect support. This library will redirect an authentication type of Office365 to OAuth and use the example AppId and Redirect URI automatically. This capability is planned for the 9.2.x version of the Microsoft.CrmSdk.XrmTooling.CoreAssembly package.

    Source: docs.microsoft.com/.../authenticate-office365-deprecation

    I use the second option: 

    class Program
        {
            static void Main(string[] args)
            {
                var connectionString = @"AuthType = Office365; Url = https://xxx.crm4.dynamics.com/;Username=xx@xxx;Password=xxx";
                CrmServiceClient crmServiceClient = new CrmServiceClient(connectionString);
    
              
                WhoAmIRequest whoAmIRequest = new WhoAmIRequest();
                WhoAmIResponse whoAmIResponse = (WhoAmIResponse)crmServiceClient.Execute(whoAmIRequest);
                Console.WriteLine("Your userId is: {0}", whoAmIResponse.UserId);
                Console.WriteLine("click to exit");
                Console.ReadLine();
            }
        }

    Edit: 

    The code is wrong !! We have to wait for version 9.2 !!

  • Stone Huang Profile Picture
    455 on at
    RE: How to connect to an organization service without using app id and redirect uri under the office 365 authentication type

    Thank you for your quickly reply.

    But this sample code supposed to be of the WS-Trust auth type, not Office 365. WS-Trust authentication will soon be abandoned.

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: How to connect to an organization service without using app id and redirect uri under the office 365 authentication type

    Hi, 

    Please refer to this sample code, it works for me.

     

    static void Main(string[] args)
            {
                var connectionString = @"AuthType = Office365; Url = https://yourOrganization.crm4.dynamics.com/;Username=xxx@xxx;Password=xxx";
                CrmServiceClient conn = new CrmServiceClient(connectionString);
    
                IOrganizationService organizationService;
                organizationService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
                WhoAmIRequest whoAmIRequest = new WhoAmIRequest();
                WhoAmIResponse whoAmIResponse = (WhoAmIResponse)organizationService.Execute(whoAmIRequest);
                Console.WriteLine("Your userId is: {0}", whoAmIResponse.UserId);
                Console.WriteLine("click to exit");
                Console.ReadLine();
            }

    Good luck

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 258

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 179

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 129 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans