dcrdev 251 Posted April 17, 2016 Share Posted April 17, 2016 So I've been thinking for a while now that I'd like to create an Emby related application. Today I started messing around with the JSON API in C#. Unfortunately I'm not entirely clear on some of the documentation in the wiki - particularly the bit bit that references providing the the hashed password values in the body. I initially tried posting the "Password" and "PasswordMD5" parameters via a normal post operation, I then tried the objects as a JSON array. Both attempts just throw back a 400 response code. Can anyone help? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using Emby.Data; using Emby.Data.Crypto; using System.Net; namespace Emby.Data.Api { public class EmbyCredentials { public string EmbyUserId { get { return EmbyClient.EmbyClientUsers().Where(x => x.Name == Settings.EmbyUser).Select(y => y.Id).ToString(); } } public string EmbyPassword { get; set; } public string EmbyPasswordMD5 { get; set; } } class EmbyAuthentication { public static Tuple<bool, string> isAuthenticated() { var _initEmby = new EmbyCredentials(); _initEmby.EmbyPasswordMD5 = PasswordHash.CreateMD5(Settings.EmbyPassword); _initEmby.EmbyPassword = PasswordHash.CreateSHA1(Settings.EmbyPassword); var embyClient = new WebClient(); var url = "http://192.168.1.2:8096/Users/AuthenticateByName?"; var param = JsonConvert.SerializeObject(_initEmby); embyClient.Headers["Content-Type"] = "application/json"; var test = embyClient.UploadString(url, param); var embyIsAuthenticated = false; var embyAuthToken = test; return Tuple.Create(embyIsAuthenticated, embyAuthToken); } } } 1 Link to comment Share on other sites More sharing options...
dcrdev 251 Posted April 17, 2016 Author Share Posted April 17, 2016 Nevermind got it: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using Emby.Data; using Emby.Data.Crypto; using System.Net; namespace Emby.Data.Api { public class EmbyCredentials { [JsonProperty(PropertyName = "Username")] public string EmbyUsername { get { return Settings.EmbyUser; } } [JsonProperty(PropertyName = "password")] public string EmbyPassword { get; set; } [JsonProperty(PropertyName = "passwordMd5")] public string EmbyPasswordMD5 { get; set; } } class EmbyAuthentication { public static Tuple<bool, string> isAuthenticated() { var embyUserId = EmbyClient.EmbyClientUsers().Where(x => x.Name == Settings.EmbyUser).Select(y => y.Id); var _initEmby = new EmbyCredentials(); _initEmby.EmbyPasswordMD5 = PasswordHash.CreateMD5(Settings.EmbyPassword); _initEmby.EmbyPassword = PasswordHash.CreateSHA1(Settings.EmbyPassword); var embyClient = new WebClient(); var url = "http://192.168.1.2:8096/Users/AuthenticateByName?format=json"; var param = JsonConvert.SerializeObject(_initEmby); var authHeader = "MediaBrowser UserId=\"" + embyUserId + "\", Client=\"Dashboard\", Device=\".NET Webclient\", DeviceId=\"" + new Guid() + "\", Version=\"1.0.0.0\""; embyClient.Headers["Content-Type"] = "application/json"; embyClient.Headers["Authorization"] = authHeader; var test = embyClient.UploadString(url, param); var embyIsAuthenticated = false; var embyAuthToken = test; return Tuple.Create(embyIsAuthenticated, embyAuthToken); } } } 1 Link to comment Share on other sites More sharing options...
dcrdev 251 Posted April 18, 2016 Author Share Posted April 18, 2016 Also I noticed that the Swagger UI is broken, it doesn't use the port defined within the emby settings. I use port 443 to access emby where as swagger is pointing at 8096. If I try accessing it via the server's local ip, everything points to my external wan address + 8096. Link to comment Share on other sites More sharing options...
Luke 37272 Posted April 18, 2016 Share Posted April 18, 2016 Hi, I would take a look at our existing c# api libraries for examples: https://github.com/MediaBrowser/Emby.ApiClient Thanks. Link to comment Share on other sites More sharing options...
dcrdev 251 Posted April 18, 2016 Author Share Posted April 18, 2016 Hi, I would take a look at our existing c# api libraries for examples: https://github.com/MediaBrowser/Emby.ApiClient Thanks. Haha thanks wish I'd seen that before writing 30+ bindings myself last night! 1 Link to comment Share on other sites More sharing options...
Untoten 296 Posted April 2, 2017 Share Posted April 2, 2017 So I've been thinking for a while now that I'd like to create an Emby related application. Today I started messing around with the JSON API in C#. Unfortunately I'm not entirely clear on some of the documentation in the wiki - particularly the bit bit that references providing the the hashed password values in the body. I initially tried posting the "Password" and "PasswordMD5" parameters via a normal post operation, I then tried the objects as a JSON array. Both attempts just throw back a 400 response code. Can anyone help? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using Emby.Data; using Emby.Data.Crypto; using System.Net; namespace Emby.Data.Api { public class EmbyCredentials { public string EmbyUserId { get { return EmbyClient.EmbyClientUsers().Where(x => x.Name == Settings.EmbyUser).Select(y => y.Id).ToString(); } } public string EmbyPassword { get; set; } public string EmbyPasswordMD5 { get; set; } } class EmbyAuthentication { public static Tuple<bool, string> isAuthenticated() { var _initEmby = new EmbyCredentials(); _initEmby.EmbyPasswordMD5 = PasswordHash.CreateMD5(Settings.EmbyPassword); _initEmby.EmbyPassword = PasswordHash.CreateSHA1(Settings.EmbyPassword); var embyClient = new WebClient(); var url = "http://192.168.1.2:8096/Users/AuthenticateByName?"; var param = JsonConvert.SerializeObject(_initEmby); embyClient.Headers["Content-Type"] = "application/json"; var test = embyClient.UploadString(url, param); var embyIsAuthenticated = false; var embyAuthToken = test; return Tuple.Create(embyIsAuthenticated, embyAuthToken); } } } Think you could craft an SSO/SAML solution for this? I would be willing to pay. 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