Can't Authenticate to get a JWT Token

A place for developers to advertise their TheTVDB.com enabled app and get help from other developers with the API.
JimAvanti
Posts: 17
Joined: Tue Dec 03, 2013 8:54 pm

Can't Authenticate to get a JWT Token

Postby JimAvanti » Tue Jun 06, 2017 3:15 pm

I need to understand the new API so I can update my program. I guess the first place to start is to experiment on the API webpage: https://api.thetvdb.com/swagger. I can’t seem to get Authentication to work. I have an APIKEY for the original API and I have a username (JimAvanti). I don’t know what to enter for “USERKEY” and I don’t know if my APIKEY will work with the new API. I keep getting “Not Authorized” with everything I try.
What is the exact format for the Authentication string when POSTing to /Login to get a JWT Token.
Thanks,
Jim

JimAvanti
Posts: 17
Joined: Tue Dec 03, 2013 8:54 pm

Re: Can't Authenticate to get a JWT Token

Postby JimAvanti » Wed Jun 07, 2017 7:58 am

I was able to get the API website working. I tried posting the token with and without quotes (I'm not sure which way worked). I do have a question about the token though. Does the Token replace the API Key that the original API used or does the token expire/change and you still need the original API key to generate a new one? In other words: do I hardcode this token in my program and authenticate with it each time the program is run?

Jim

JimAvanti
Posts: 17
Joined: Tue Dec 03, 2013 8:54 pm

Re: Can't Authenticate to get a JWT Token

Postby JimAvanti » Fri Jun 09, 2017 3:19 pm

Okay, so I guess I am the only one answering my questions. Playing around on the API2 test website I noticed I could not refresh the token today. I had to use my original API key to get a new JWT token and it was different that the first one I got so I guess it does change and so the original API Key is still required. When making WebRequests with the original API it is a simple matter of sending the URL to the API and getting a response to parse. I can’t figure out how to do this with the new API. How do you pass the token to the new API in a WebRequest? Anyone? It seems that every request requires the token to be sent somehow.

Jim

Taloth Saldono
Posts: 19
Joined: Sun Apr 17, 2016 2:25 am

Re: Can't Authenticate to get a JWT Token

Postby Taloth Saldono » Tue Jun 13, 2017 9:48 am

Maybe you should read the first page on swagger. It quite explicitly states what you should do with the token, how to obtain it, how to use it and how to refresh it.

Also: https://jwt.io/#debugger and read up on JWT.

JimAvanti
Posts: 17
Joined: Tue Dec 03, 2013 8:54 pm

Re: Can't Authenticate to get a JWT Token

Postby JimAvanti » Tue Jun 13, 2017 12:53 pm

I have been having success with the Swagger API site (https://api.thetvdb.com/swagger#/). Are you saying there is a full swagger site other than the API page with documentation? I will look for it. I will also read up on the JWT token. I wasn't even sure if JWT was something standard or just something TheTVdb uses. This is all very new to me and I am not finding any useable information anywhere.

Thanks,
Jim

Taloth Saldono wrote:Maybe you should read the first page on swagger. It quite explicitly states what you should do with the token, how to obtain it, how to use it and how to refresh it.

Also: https://jwt.io/#debugger and read up on JWT.

DarklightIndigo
Just zis guy, you know?
Posts: 7645
Joined: Sun Apr 27, 2014 9:16 am
Location: San Francisco
Contact:

Re: Can't Authenticate to get a JWT Token

Postby DarklightIndigo » Tue Jun 13, 2017 1:43 pm

That's the one, there should be dropdowns for the various functions, just after the Versioning section. Clicking "Expand Operations" on any of those should give detailed - if generic - implementation directions.
Strangers are just the friends we haven't met yet.

Taloth Saldono
Posts: 19
Joined: Sun Apr 17, 2016 2:25 am

Re: Can't Authenticate to get a JWT Token

Postby Taloth Saldono » Tue Jun 13, 2017 2:42 pm

Jim, that's why I gave you the link to jwt.io, to get you to read up on the various terms since that'll help you to make sense of the api. the JWT token, the Authentication header (a HTTP header, google it), REST api... It's a bit of jargon, but it's pretty standard stuff.
The Authentication paragraph on the swagger page (in the middle of the screen when you open it), explains in a few words what's involved. Once you understand those terms, the pieces of the puzzle will hopefully fall into place.

PS: That 'swagger' site is not the api, it's just the documentation and experimentation UI. Explaining how you can use the api.

JimAvanti
Posts: 17
Joined: Tue Dec 03, 2013 8:54 pm

Re: Can't Authenticate to get a JWT Token

Postby JimAvanti » Tue Jun 13, 2017 3:31 pm

There is a free JWT handbook on the site you sent me, but I can't seem to get it. I even created a Auth0 account. It has a button that says "Pay with a Tweet" but it does nothing. Maybe because I don't have Twitter? Does anyone have a copy of the handbook? It should be free and in pdf format.

Jim

Taloth Saldono wrote:Maybe you should read the first page on swagger. It quite explicitly states what you should do with the token, how to obtain it, how to use it and how to refresh it.

Also: https://jwt.io/#debugger and read up on JWT.

JimAvanti
Posts: 17
Joined: Tue Dec 03, 2013 8:54 pm

Re: Can't Authenticate to get a JWT Token

Postby JimAvanti » Tue Jun 13, 2017 4:33 pm

I just realized one of my problems! I am using Visual Studio 2010 and the highest targeted .NET framework available is 4.0 while JWT was first introduced in version 4.5. That explains a lot!

Taloth Saldono
Posts: 19
Joined: Sun Apr 17, 2016 2:25 am

Re: Can't Authenticate to get a JWT Token

Postby Taloth Saldono » Fri Jun 16, 2017 1:05 am

Sry for not replying sooner.

The JWT handbook is probably a bit too detailed, it wasn't my intention to send you down into that rabbit hole. I just wanted to make sure you know the general idea behind JWT. The how do jwt tokens work is a nice explanation of that because it's a bit more detailed than on the tvdb swagger page.

So you don't need any 'JWT-support' in Visual studio to use it, for our purpose it's just a string that you need to send in the Authorization header.