TheShanMan 34 Posted May 7, 2018 Share Posted May 7, 2018 In powershell, I'm doing the following: $authresponse = Invoke-RestMethod -uri http://myserver:8096/Users/AuthenticateByName?format=json -Method Post -Headers @{"Authorization"="MediaBrowser Client=`"powershell`", Device=`"foobar`", DeviceId=`"foobar`", Version=`"1.0`""} -Body @{ username="me"; password="sha1encodedpassword" } And I get an AccessToken back in the response. I seem to have to add dashes to it now (that seems to be a change from the past) but now when I use that access token in the following, I get "access token is invalid or expired". Invoke-RestMethod -uri http://myserver:8096/Library/Refresh -Method Post -Headers @{ "X-MediaBrowser-Token"="09c97661-47fb-420b-af35-aadbeef21487" } What am I missing? Incidentally, I'm trying to recover from an apparent change to how the refresh api works because my script stopped working a few weeks ago complaining that appVersion was null. Link to comment Share on other sites More sharing options...
Luke 37116 Posted May 7, 2018 Share Posted May 7, 2018 Hi, I would suggest reviewing our api docs to make sure you are complying with all of the authentication requirements: https://github.com/MediaBrowser/Emby/wiki Thanks. Link to comment Share on other sites More sharing options...
TheShanMan 34 Posted May 7, 2018 Author Share Posted May 7, 2018 I've been trying, but for some reason I don't find them to be particularly helpful. I've never had much luck following what the Auth page says and I couldn't find any coverage of the Refresh call. Link to comment Share on other sites More sharing options...
TheShanMan 34 Posted May 7, 2018 Author Share Posted May 7, 2018 (edited) I guess I need to be a little more direct: Why am I getting an invalid or expired access token back from my auth call? Edited May 7, 2018 by TheShanMan Link to comment Share on other sites More sharing options...
Luke 37116 Posted May 7, 2018 Share Posted May 7, 2018 I can't tell from the above information. Someone will have to trace it down by finding what is missing from your api requests. You can do that by comparing to our documentation, and/or comparing to what our own api libraries do. For example, our javascript library: https://github.com/MediaBrowser/Emby.ApiClient.Javascript Link to comment Share on other sites More sharing options...
TheShanMan 34 Posted May 7, 2018 Author Share Posted May 7, 2018 Thanks! That helped a little though by no means is it user friendly. I finally figured it out. At some point in my trial and error I saw an error message that indicated I needed dashes in the token (GUID style) so from that point forward I was inserting dashes and that was the problem. I believe what started making my script fail a few weeks ago was my token probably expired but the error message is very misleading (said appVersion was null). I'm not sure how long tokens are valid but I created it once and just kept using the hard coded value. And I think previously the "Authorization" header wasn't required in the AuthenticateByName call (at least I don't think I ever did that). So I needed to renew my token and the AuthenticateByName comment I had in my script was missing the Authorization header. So once I fixed that, my script started working again. And now I've changed my script to call AuthenticateByName every time so hopefully that prevents my script from breaking at some seemingly random point in time in the future again. Here's my new script which is now working: $body = @{ username="me"; password="sha1password" } $headers = @{"Authorization"="MediaBrowser Client=`"powershell`", Device=`"foobar`", DeviceId=`"foobar`", Version=`"1.0`""} $authresponse = Invoke-RestMethod -uri http://myserver:8096/Users/AuthenticateByName?format=json -Method Post -Headers $headers -Body $body $headers = @{ "X-MediaBrowser-Token"=$authresponse.AccessToken } Invoke-RestMethod -uri http://myserver:8096/Library/Refresh -Method Post -Headers $headers Link to comment Share on other sites More sharing options...
Luke 37116 Posted May 7, 2018 Share Posted May 7, 2018 Thanks for the info. Link to comment Share on other sites More sharing options...
PenkethBoy 2063 Posted May 7, 2018 Share Posted May 7, 2018 have you forgotten this thread which i think you started? https://emby.media/community/index.php?/topic/31789-rest-authentication-started-failing-with-build-5886/?p=324107 the second to last post has a working way to authenticate and get your access token for the user Link to comment Share on other sites More sharing options...
TheShanMan 34 Posted May 7, 2018 Author Share Posted May 7, 2018 No, I didn't. Thanks though! 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