Jump to content

c# credentialProvider


Hydro

Recommended Posts

Hi
 
I try to create a plugin for my home automation system to control emby.
My home automation use c# plugins.
 
So i install https://github.com/MediaBrowser/Emby.ApiClient with nugget and try the  multi-server example. But i'm stuck at CredentialProvider.
 
If i understand, i need to implement my own ICredentialProvider but i don't know how to do this.
 
Is anyone having more informations about that point ?
 
My code so far :

using Constellation.Package;
using MediaBrowser.ApiInteraction;
using MediaBrowser.Model.Session;
using MediaBrowser.Model.Logging;
using MediaBrowser.ApiInteraction.Cryptography;
using MediaBrowser.ApiInteraction.Net;
using MediaBrowser.ApiInteraction.WebSocket;

namespace Emby
{
    public class Program : PackageBase
    {
        static void Main(string[] args)
        {
            PackageHost.Start<Program>(args);
        }

        public override void OnStart()
        {
            PackageHost.WriteInfo("Package starting - IsRunning: {0} - IsConnected: {1}", PackageHost.IsRunning, PackageHost.IsConnected);

            var logger = new NullLogger();

            var capabilities = new ClientCapabilities();

            var device = new Device
            {
                DeviceName = "My Device Name",
                DeviceId = "My Device Id"
            };

            var credentialProvider = new CredentialProvider();

            // If using the portable class library you'll need to supply your own INetworkConnection implementation.
            var networkConnection = new NetworkConnection(logger);

            // If using the portable class library you'll need to supply your own ICryptographyProvider implementation.
            var cryptoProvider = new CryptographyProvider();

            // If using the portable class library you'll need to supply your own IServerLocator implementation.
            var serverLocator = new ServerLocator(logger);

            var connectionManager = new ConnectionManager(logger,
                 credentialProvider,
                 networkConnection,
                 serverLocator,
                 "My App Name",
                 // Application version
                 "1.0.0.0",
                 device,
                 capabilities,
                 cryptoProvider,
                 ClientWebSocketFactory.CreateWebSocket);
        }
    }
}
 

Thank for your help !

Link to comment
Share on other sites

chef

Hydro, I PM'd you. When building a plugin, you don;t need a connection manager.

 

I can help :)

 

You'll see in my source code how to interface the plugin, and also how to attach events, and how to integrate other WEB-APIs into your plugin.

 

The Plugin API has all the objects you need to send HTTP requests to other webAPi's, you'll see that in my plugin source.

 

Note: ignore all the MiOS/Vera code and take a close look at the "Plugin.cs", the "PluginConfiguration.cs"

 

You'll notice that the C# code integrates itself into the Javascript/JQuery,  on the Emby HTML configuration pages, through XML.

 

It sounds way more complicated then it is.

 

 

I'm sure we'll be in touch shortly.

 

What HomeAutomation devices are you wanting to integrate?

 

Ben

Edited by chef
Link to comment
Share on other sites

As i said to chef, i'm building a plugin for my HA to control emby not a plugin for emby to control my HA :)

 

With his help i came to that code :

using Constellation.Package;
using MediaBrowser.ApiInteraction;
using MediaBrowser.Model.Session;
using MediaBrowser.Model.Logging;
using MediaBrowser.ApiInteraction.Cryptography;
using System.Threading.Tasks;

namespace Emby
{
    public class Program : PackageBase
    {
        static void Main(string[] args)
        {
            PackageHost.Start<Program>(args);
        }

        public override void OnStart()
        {
            PackageHost.WriteInfo("Package starting - IsRunning: {0} - IsConnected: {1}", PackageHost.IsRunning, PackageHost.IsConnected);

            var AuthTest = new Auth();
            
        }

        public class Auth
        {

            public async Task Connect()
            {

                var logger = new NullLogger();

                var capabilities = new ClientCapabilities();

                var device = new Device
                {
                    DeviceName = "My Device Name",
                    DeviceId = "My Device Id"
                };

                var cryptoProvider = new CryptographyProvider();

                var client = new ApiClient(logger, "192.168.1.50:8096", "Constellation", device, "0.0.0.1", cryptoProvider);

                var authResult = await AuthenticateUserAsync("username", passwordHash);

            }



        }

    }
}

But i've got an error on "var authResult = await AuthenticateUserAsync("username", passwordHash);", it doesn't find AuthenticateUserAsync  :(

Link to comment
Share on other sites

chef

You have to use:

 

Await client.AuthenticateUserasync

 

So try

 

var authresult = await client.Authenticate.....

 

 

Also try and put the authentication into a try and catch, because it will error if the user name and password is wrong.

Edited by chef
Link to comment
Share on other sites

My code so far if someone need :

using MediaBrowser.ApiInteraction;
using MediaBrowser.Model.Session;
using MediaBrowser.Model.Logging;
using MediaBrowser.ApiInteraction.Cryptography;
using System.Threading.Tasks;
using System;


namespace Emby
{
    public class Program : PackageBase
    {
        static void Main(string[] args)
        {
            Connect();
        }


        public void Connect()
        {


            var test = ConnectToEmby();


        }
        
        async Task<MediaBrowser.Model.Users.AuthenticationResult> ConnectToEmby()
        {


                var logger = new NullLogger();
                var capabilities = new ClientCapabilities();
                var device = new Device
                {
                    DeviceName = "MIDGARD",
                    DeviceId = "My Device Id"
                };
                var cryptoProvider = new CryptographyProvider();
                var client = new ApiClient(logger, "http://192.168.1.50:8096", "Constellation", device, "Constellation", cryptoProvider);


                var authResult = new MediaBrowser.Model.Users.AuthenticationResult();
                try
                {
                    authResult = await client.AuthenticateUserAsync("Alpha", "");
                }
                catch (Exception e)
                {
                    Console.log("{0} Exception caught.", e);
                }


            return authResult;
         }


    }
}

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...