Jump to content

Api sessions problem


Recommended Posts

Posted (edited)

Hey

 

I want to create a plugin for my home automation that control Media Browser.

 

So i try to use API with Swagger UI. I use Sessions to retreive my session id (for MBT), then i try Playing/Unpause or Command/Gohome but every time it can't find session.

 

Any idea ?

 

Thank

Edited by Hydro
  • 2 months later...
Posted

Ok thank for your link.

 

I tried to use authentification but i didn't achieve.

 

 

 

  • Device is the product name of the device
  • DeviceId is the device's unique id
  • Client is the type of client (Android, Dashboard, Dlna, iOS, PC, WindowsPhone, WindowsRT, other)
  • Version is the client application version
  • UserId is the Id of the current logged in user (if there is one).

 

I manage to found UserId, where i find the others ?

ScottIsAFool
Posted

I manage to found UserId, where i find the others ?

You provide the rest as it all relates to your app and the device it's being run on.

  • Like 1
Posted

For exemple Media Browser Theather :

 

Client : Media Brower Theather

Device : PC

Device Id : ??

Version : 3.0.5465.31343

 

What's the device id ?

 

Thank you :)

Posted

It needs to be something unique for that device.  Most devices have this and some sort of API call to get it.  If yours doesn't, then create a GUID and save it on first run and then use that in the future.  Make sure it is unique but consistent on the same device.

Posted

So for example to control my htpc (windows) with api i must create an id with GUID ?

Posted

You need to identify the device that is communicating with the API so, yes.

Posted

Ok so i try to send http request with firefox addon to AuthenticateByName :

 

Header :

 

Authorization : MediaBrowser

UserId : my user id

Client : PC

Device : Alpha

DeviceId : 123456

Version : 1.0.0

 

Content to send :

 

Content type : application/json

Content : username : Hydro

 

Answer :

 

 

 

Response Status Error Code RequestBindingException Message Unable to bind request Stack Trace à ServiceStack.Host.RestHandler.CreateRequest(IRequest httpReq, IRestPath restPath) à ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)

 

If i try to send http request to Sessions for example :

 

 

 

Response Status Error Code SecurityException Message Access token is invalid or expired. Stack Trace à MediaBrowser.Server.Implementations.HttpServer.Security.AuthService.ValidateSecurityToken(IServiceRequest request, String token) à MediaBrowser.Server.Implementations.HttpServer.Security.AuthService.ValidateUser(IServiceRequest request, IAuthenticationAttributes authAttribtues) à MediaBrowser.Server.Implementations.HttpServer.Security.AuthService.Authenticate(IServiceRequest request, IAuthenticationAttributes authAttribtues) à MediaBrowser.Controller.Net.AuthenticatedAttribute.RequestFilter(IRequest request, IResponse response, Object requestDto) à ServiceStack.ServiceStackHost.ApplyRequestFiltersSingle(IRequest req, IResponse res, Object requestDto) à ServiceStack.ServiceStackHost.ApplyRequestFilters(IRequest req, IResponse res, Object requestDto) à ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)
Posted

You can't use a tool like that unless you can supply proper headers and, before you can send any request other than very basic public ones, you need to authenticate and get a proper token in the header.

Posted (edited)

Ok so i use firebug to see http request, i try to copy this request with chrome extension (postman) :

 

Header :

 

 

 

Authorization  MediaBrowser Client="Dashboard", Device="Firefox 30.0", DeviceId="...", Version="3.0.5476.2552"

 

Post :

 

 

 

Username
"Hydro" password
"da39a3ee5e6b4b0d3255bfef95601890afd80709"

 

But every time i try i've got :

 

 

{"ResponseStatus":{"ErrorCode":"SecurityException","Message":"Access token is invalid or expired.","StackTrace":" à MediaBrowser.Server.Implementations.HttpServer.Security.AuthService.ValidateSecurityToken(IServiceRequest request, String token)\r\n à MediaBrowser.Server.Implementations.HttpServer.Security.AuthService.ValidateUser(IServiceRequest request, IAuthenticationAttributes authAttribtues)\r\n à MediaBrowser.Server.Implementations.HttpServer.Security.AuthService.Authenticate(IServiceRequest request, IAuthenticationAttributes authAttribtues)\r\n à MediaBrowser.Controller.Net.AuthenticatedAttribute.RequestFilter(IRequest request, IResponse response, Object requestDto)\r\n à ServiceStack.ServiceStackHost.ApplyRequestFiltersSingle(IRequest req, IResponse res, Object requestDto)\r\n à ServiceStack.ServiceStackHost.ApplyRequestFilters(IRequest req, IResponse res, Object requestDto)\r\n à ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)"}}

Edited by Hydro
Posted

i would refer to our ApiClient libraries for examples:

 

https://github.com/MediaBrowser

 

available in .NET, Java and Javascript.

 

And/or review sample code from any of our open source apps, because they all use authentication.

  • 3 weeks later...
Posted

@@Hydro

 

what language will your authomation plug-in be written in?

 

What automation application rare you looking to port to MB?

 

If you follow Lukes advice by utilizing the API libraries you will find it much, much easier.

 

If you are coding in .net, then i would like to help you because I would also like to get my home automation devices up and running (I also know of a couple other memebers who would like to see this come together).

 

Lets talk! ;)

 

"@" me when you read this.

 

I have endless source material and knowlegde of the API  to help, and I also have written basic Automation code for EventGhost.

  • Like 1
Posted

@@chef Thank for your reply !

 

My home automation system use plugin system. Plugins must use php / js / HTML.

 

Basically I want to be able to remote control player and see the status.

Posted (edited)

Well I am not very good at web based coding, I mostly only know vb and C#. But all is not at an end.

 

Have you looked at any of the libraries on GitHub for media browser. I can post a header example from my kinect application here in a moment.

 

It might help. I will return :)

 

Edit: to follow up what ebr mentioned above.

 

You need to request a list of public user names from the server.

 

In most cases the request will return a data transfer object for each user you have created in media browser.

 

With that information you then need to have the client object you have created to call the (I think I remember this correctly) "AuthenticateUser".

 

The "AuthenticateUser" routine will have some overloads with which you can fill in based on what was returned by your public user request.

 

After the user has been authenticated you will be able to request further information from the server regarding sessions and media item info.

Edited by chef

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