locked
MS dynamics CRM UW for IOT - Authentication problems RRS feed

  • Question

  • Hello,

    I am developing an UWP app for MS dynamics CRM (online 2016). I just have built the authentication and pull some demo data. While debugging on my local machine, everything works well, but when I try to debug remotly on my Raspberry Pi, the authentication window does not open for entering my login data.

    I registered the app in Azure AD as Native Client Application, according to this guide: https://msdn.microsoft.com/en-us/library/mt622431.aspx?f=255&MSPPError=-2147217396 

    Then I used the information and demo code for mobile applications from the 2016 SDK.

    My authentication looks like this:

    public static class CurrentEnvironment
        {
            # region Class Level Members
    
            private static AuthenticationContext _authenticationContext;
    
            private const string _clientID = "MYID";
            public const string CrmServiceUrl = "https://MYORG.crm4.dynamics.com";
    
            # endregion
            public static async Task<string> Initialize()
            {
                Uri serviceUrl = new System.Uri(CrmServiceUrl + "/XRMServices/2011/Organization.svc/web?SdkClientVersion=6.1.0000.0000");
    
                string _oauthUrl = DiscoveryAuthority(serviceUrl);
    
                //Uri redirectUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
                Uri redirectUri = new Uri("ms-app://MYURI");
    
                _authenticationContext = new AuthenticationContext(_oauthUrl, false);
                AuthenticationResult result = await _authenticationContext.AcquireTokenAsync(CrmServiceUrl, _clientID, redirectUri);
    
                if (result.Status != AuthenticationStatus.Success)
                {
                    if (result.Error == "authentication_failed")
                    {
                        // Try again.
                        _authenticationContext = new AuthenticationContext(_oauthUrl, false);
                        result = await _authenticationContext.AcquireTokenAsync(CrmServiceUrl, _clientID, redirectUri);
                    }
                    else
                    {
                        DisplayErrorWhenAcquireTokenFails(result);
                    }
                }
                return result.AccessToken;
            }
    ...

    Can anyone give me a hint, what I need to change? I primarily want to build the application for windows 10 IOT on Raspberry Pi 2.

    Thank you!

    Monday, February 1, 2016 3:13 PM

All replies

  • Hi,

    according to Jason Lattimers Blogpost (https://community.dynamics.com/crm/b/jasonlattimersblog/archive/2015/11/23/crm-web-api-universal-windows-platform-using-c), I tried to use the WebAccountProvider to do the authorization. But the same thing happened:

    Deploying to my local machine in Debug mode worked well! But when I try to deploy remotly to my RaspberryPi running Windows 10 IOT, the Window to enter the credentials does not open!

    Can anyone give me a hint?

    Here is the Code for the WebAccountProvider Authentication:

     public static class CurrentEnvironment
        {
            # region Class Level Members

    private const string _clientID = "[MYCLIENTID]"; public const string CrmServiceUrl = "https://MYCRMORG.crm4.dynamics.com"; private const string _authority = "https://login.microsoftonline.com/common/oauth2/authorize"; private static string _accessToken; # endregion public static async Task<string> Initialize() { //var redirect = GetAppRedirectURI(); try { WebAccountProvider wap = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", _authority); WebTokenRequest wtr = new WebTokenRequest(wap, string.Empty, _clientID); wtr.Properties.Add("resource", CrmServiceUrl); WebTokenRequestResult wtrr = await WebAuthenticationCoreManager.RequestTokenAsync(wtr); if (wtrr.ResponseStatus == WebTokenRequestStatus.Success) { _accessToken = wtrr.ResponseData[0].Token; } } catch (Exception ex) { } return _accessToken; }

    Thanks!

    Markus



    • Edited by markus.hauf Wednesday, February 3, 2016 7:26 AM changed code
    Wednesday, February 3, 2016 7:24 AM
  • Well, finally I got it!

    The Authentication via WebAccountProvider is only possible on devices with a browser.

    Thanls to Vittorio Bertocci I used the methos described here:

    https://blogs.msdn.microsoft.com/iot/2016/01/26/using-power-bi-to-visualize-sensor-data-from-windows-10-iot-core/

    and

    https://azure.microsoft.com/en-us/documentation/samples/active-directory-dotnet-deviceprofile/

    to perform headless authentication.

    Thursday, February 4, 2016 3:34 PM