Skip to main content

Notifications

Announcements

No record found.

Customer Service forum

Connect to Dynamics 365 (online) (Office 365) using OAuth with Single Sign On

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi, I am trying to connect to the Dynamics organizationservice via single sign on to Azure AD. I cannot find any code sample that works without providing username AND password. We created an App Registration in Azure AD and use it in the code below.

This is the code that should work, but it doesn't connect.

Can anybody help?

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim region As String = String.Empty
    Dim orgName As String = String.Empty
    Dim isOnPrem As Boolean = False
    Dim originalUrl As String = "do.api.crm4.dynamics.com/.../organization.svc"

    Utilities.GetOrgnameAndOnlineRegionFromServiceUri(New Uri(originalUrl), region, orgName, isOnPrem)

    Dim path As String = IO.Path.Combine(IO.Path.GetTempPath(), "oauth-cache.txt")

    Dim crmSvc = New CrmServiceClient(CrmUserId, CrmServiceClient.MakeSecureString(crmPassword),
                    region,
                    orgName,
                    False,
                    Nothing,
                    Nothing,
                    "74c5e5c9-52db-4cee-54cb-e213e8f223ea",
                    New Uri("http://crm.company.nl"),
                    path, Nothing, Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior.Auto)

    '' crmSvc.isReady is FALSE.

    crmSvc = New CrmServiceClient(CrmUserId, CrmServiceClient.MakeSecureString(crmPassword),
                    region,
                    orgName,
                    True,
                    True,
                    Nothing,
                    True)
 
    '' crmSvc.isReady is TRUE.

    MessageBox.Show(crmSvc.IsReady.ToString())

  End Sub

Categories:
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Connect to Dynamics 365 (online) (Office 365) using OAuth with Single Sign On

    Thanks, we are using this:

    docs.microsoft.com/.../how-to-connect-sso

    to prevent that users get prompted with a login and password.

    This works when navigating to dynamics CRM in the browser, but we have no clue how to get this working when connecting to the organization-service.

    We can get it working like you said: when no credentials are specified, we get a prompt, but this is not the wanted behavior

  • Mahadeo Matre Profile Picture
    Mahadeo Matre 17,021 on at
    RE: Connect to Dynamics 365 (online) (Office 365) using OAuth with Single Sign On

    Hi,

    As per Microsoft documentations, if user credentials aren't specified, ADAL  prompts the user to provide the credentials depending on the PromptBehavior.

    Try changing PromptBehavior.Auto to PromptBehavior.RefreshSession

    Here are details on OAuth

    docs.microsoft.com/.../use-crmserviceclient-constructors-connect

    and PromptBehavior

    https://msdn.microsoft.com/en-us/library/microsoft.identitymodel.clients.activedirectory.promptbehavior.aspx 

    hope this will help..

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,503 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans