Skip to main content

Notifications

Announcements

No record found.

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

Posted on by 384

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

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 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
    Stone Huang 384 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
    meelamri 13,204 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
    meelamri 13,204 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
    Stone Huang 384 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
    meelamri 13,204 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans