WindowsDevicePortalWrapper icon indicating copy to clipboard operation
WindowsDevicePortalWrapper copied to clipboard

LaunchApplicationAsync() throws 'Unauthorized' exception

Open DavidRatliff opened this issue 7 years ago • 7 comments

I am attempting to remotely launch a Hololens application. My code, as posted below, throws an 'Unauthorized' exception. To my understanding, this exception is used for missing or incorrect credentials, but that cannot be the case, as the portal connection opens successfully. I am running this project as a UWP from the Unity Editor. Any help is greatly appreciated!

private async Task LaunchApplication()
    {
        try
        {
            Debug.Log("Launching...");
            await portal.LaunchApplicationAsync(appid, packageName);
            Debug.Log("Launched");
        }
        catch (DevicePortalException e)
        {
            Debug.Log(e.Reason);
        }
    }

DavidRatliff avatar Nov 23 '17 19:11 DavidRatliff

Hi David,

Is there any chance you're running this with the connection address at loopback/localhost?

Does every app you're attempting to launch fail with this?

Thanks, Hirsch


From: DavidRatliff [email protected] Sent: Thursday, November 23, 2017 11:41:52 AM To: Microsoft/WindowsDevicePortalWrapper Cc: Subscribed Subject: [Microsoft/WindowsDevicePortalWrapper] LaunchApplicationAsync() throws 'Unauthorized' exception (#279)

I am attempting to remotely launch a Hololens application. My code, as posted below, throws an 'Unauthorized' exception. To my understanding, this exception is used for missing or incorrect credentials, but that cannot be the case, as the portal connection opens successfully. I am running this project as a UWP from the Unity Editor. Any help is greatly appreciated!

private async Task LaunchApplication() { try { Debug.Log("Launching..."); await portal.LaunchApplicationAsync(appid, packageName); Debug.Log("Launched"); } catch (DevicePortalException e) { Debug.Log(e.Reason); } }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMicrosoft%2FWindowsDevicePortalWrapper%2Fissues%2F279&data=02%7C01%7Chirsin%40microsoft.com%7Cfe1c4ccb9f554093dc2208d532aa3f64%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636470629148047611&sdata=xQZ2l2X91BY4T2XhJk%2FsUd0NubW%2F%2BYcU%2FfrUHuy7fEQ%3D&reserved=0, or mute the threadhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABltO2wX40JwW1ugn_dFrFrK9KlXMW-Yks5s5cqAgaJpZM4QpIk9&data=02%7C01%7Chirsin%40microsoft.com%7Cfe1c4ccb9f554093dc2208d532aa3f64%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636470629148047611&sdata=mwwoa5kg2n6XoQE1IsyaiDcNMnszVkk3EsqODoAsPSo%3D&reserved=0.

hpsin avatar Nov 23 '17 19:11 hpsin

I have tried connecting at localhost and via internet, and with several different apps. All produce this exception. Thanks for the response!

DavidRatliff avatar Nov 27 '17 22:11 DavidRatliff

Hm - do the other REST APIs work? e.g. you can get the device family? One thing to be aware of is that there might be two LaunchApplication APIs, one of which is for IoT.

hpsin avatar Nov 30 '17 17:11 hpsin

Yes, upon connection I can successfully retrieve the Hololens IP, OS version, and device family.

If I'm reading the documentation correctly, there is only a single LaunchApplication request type, used for both Hololens and IoT.

DavidRatliff avatar Nov 30 '17 17:11 DavidRatliff

Ah, yes, you're correct. Can you share how you're getting the AppId and the packageName?

hpsin avatar Nov 30 '17 17:11 hpsin

Apologies for the inactivity, it's been finals season for me. I'm pulling that information manually from the response to the /api/app/packagemanager/packages request. For example:

appid = "Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge" packageName = "Microsoft.MicrosoftEdge_38.14393.1770.0_neutral__8wekyb3d8bbwe"

DavidRatliff avatar Dec 16 '17 23:12 DavidRatliff

I got it working by changing the auth to basic auth.

in HttpHeadersHelpers I added

private void ApplyHttpHeaders(
    HttpClient client,
    HttpMethods method)
{
    var byteArray = Encoding.ASCII.GetBytes($"{deviceConnection.Credentials.UserName}:{deviceConnection.Credentials.Password}");
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
    this.ApplyUserAgentHeader(client);
    this.ApplyCSRFHeader(client, method);
}

and I removed the credential stuff from the HttpClientHandler initializations

new HttpClientHandler
{
     //UseDefaultCredentials = false,
     //Credentials = this.deviceConnection.Credentials,
    ....
}

smstuebe avatar Feb 12 '18 17:02 smstuebe