Hydro 5 Posted October 15, 2014 Share Posted October 15, 2014 (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 October 15, 2014 by Hydro Link to comment Share on other sites More sharing options...
Luke 37067 Posted October 15, 2014 Share Posted October 15, 2014 Take a look at this: https://github.com/MediaBrowser/MediaBrowser/wiki/Authentication Link to comment Share on other sites More sharing options...
Hydro 5 Posted December 22, 2014 Author Share Posted December 22, 2014 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 ? Link to comment Share on other sites More sharing options...
ScottIsAFool 517 Posted December 23, 2014 Share Posted December 23, 2014 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. 1 Link to comment Share on other sites More sharing options...
Hydro 5 Posted December 23, 2014 Author Share Posted December 23, 2014 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 Link to comment Share on other sites More sharing options...
ebr 14913 Posted December 23, 2014 Share Posted December 23, 2014 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. Link to comment Share on other sites More sharing options...
Hydro 5 Posted December 23, 2014 Author Share Posted December 23, 2014 So for example to control my htpc (windows) with api i must create an id with GUID ? Link to comment Share on other sites More sharing options...
ebr 14913 Posted December 23, 2014 Share Posted December 23, 2014 You need to identify the device that is communicating with the API so, yes. Link to comment Share on other sites More sharing options...
Hydro 5 Posted December 24, 2014 Author Share Posted December 24, 2014 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) Link to comment Share on other sites More sharing options...
ebr 14913 Posted December 24, 2014 Share Posted December 24, 2014 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. Link to comment Share on other sites More sharing options...
Hydro 5 Posted December 29, 2014 Author Share Posted December 29, 2014 (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 December 29, 2014 by Hydro Link to comment Share on other sites More sharing options...
Luke 37067 Posted December 29, 2014 Share Posted December 29, 2014 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. Link to comment Share on other sites More sharing options...
chef 3745 Posted January 14, 2015 Share Posted January 14, 2015 @@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. 1 Link to comment Share on other sites More sharing options...
Hydro 5 Posted January 14, 2015 Author Share Posted January 14, 2015 @@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. Link to comment Share on other sites More sharing options...
chef 3745 Posted January 14, 2015 Share Posted January 14, 2015 (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 January 14, 2015 by chef Link to comment Share on other sites More sharing options...
Angelblue05 4130 Posted January 15, 2015 Share Posted January 15, 2015 I just finished building my extension, I'm a new learner, but you can check the login process in js. I've commented a lot, because I needed to back track a lot. Maybe it can give you a better idea of what's expected when you authenticate a user. https://github.com/angelblue05/MB3-Upcoming/blob/master/popup.js 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now