WindowsDevicePortalWrapper
WindowsDevicePortalWrapper copied to clipboard
LaunchApplicationAsync() throws 'Unauthorized' exception
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);
}
}
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.
I have tried connecting at localhost and via internet, and with several different apps. All produce this exception. Thanks for the response!
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.
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.
Ah, yes, you're correct. Can you share how you're getting the AppId and the packageName?
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"
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,
....
}