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

Authentication #34

Open
JamesM85 opened this issue Jan 17, 2016 · 2 comments
Open

Authentication #34

JamesM85 opened this issue Jan 17, 2016 · 2 comments

Comments

@JamesM85
Copy link

Hi,
Has there been any further progress on this project? I have been trying to get it to work on my windows phone, which it does locally but not remotely.

It doesn't appear that the original code save the credentials or attempted to pass them to the uri.

I've got to the stage now where they are saving and I'm trying to pass them to openhab here:

    public Uri ResolveRemoteUrl()
    {
        if (string.IsNullOrEmpty(RemoteHostname))
            return null;

        try
        {
            var scheme = UseHttps ? "https" : "http";
            UriBuilder builder;
            if (PortNumber.HasValue)
                builder = new UriBuilder(scheme, RemoteHostname, PortNumber.Value);

            else
                builder = new UriBuilder(scheme, RemoteHostname);

            builder.UserName = Username;   /// Added for Authentication
            builder.Password = Password;     /// Added for Authentication

            return builder.Uri;
        }
        catch
        {
            return null;
        }
    }

But it seems to fail. Any progress updates would be really appreciated. I'd love to get some sort of working windows phone interface for openhab.

James

@JamesM85
Copy link
Author

I just thought i'd follow up, in case anyone is following this. I've sort of got authentication working now, as below:
private HttpClient GetWebClient()
{
var filter = new HttpBaseProtocolFilter();
//filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted); - not needed when cert is installed
filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName);

        var httpClient = new HttpClient(filter);

        // Add an Accept header for JSON format.
        httpClient.DefaultRequestHeaders.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("application/json"));

        // Add an Charset header for Unicode.
        httpClient.DefaultRequestHeaders.Add("Accept-Charset", "utf-8");

     httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + Convert.ToBase64String(StringToAscii(string.Format("{0}:{1}", Username, Password ))));
        return httpClient;

    }

@kobush
Copy link
Owner

kobush commented Jan 20, 2016

Hi James,
I apologize for keeping silent. I'm currently swamped with other work and unfortunately while I'd love to can't do much on the project. Still hoping I can pick up sooner than later.

Thanks for contributing your solution. I'll try to modify the code soon.

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

2 participants