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 Service forum

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

(0) ShareShare
ReportReport
Posted on by

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:
I have the same question (0)
  • Mahadeo Matre Profile Picture
    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..

  • Community Member Profile Picture
    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

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 > Customer Service

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans