Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaunchApplicationAsync() throws 'Unauthorized' exception #279

Open
DavidRatliff opened this issue Nov 23, 2017 · 7 comments
Open

LaunchApplicationAsync() throws 'Unauthorized' exception #279

DavidRatliff opened this issue Nov 23, 2017 · 7 comments

Comments

@DavidRatliff
Copy link

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);
        }
    }
@hpsin
Copy link
Contributor

hpsin commented Nov 23, 2017 via email

@DavidRatliff
Copy link
Author

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

@hpsin
Copy link
Contributor

hpsin commented Nov 30, 2017

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.

@DavidRatliff
Copy link
Author

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.

@hpsin
Copy link
Contributor

hpsin commented Nov 30, 2017

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

@DavidRatliff
Copy link
Author

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"

@smstuebe
Copy link

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,
    ....
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants