Using JWT and connecting to server

  • Thread starter Thread starter MrSnert
  • Start date Start date
M

MrSnert

Guest
Hi,

This is probably in the wrong forum. Everything I post seems to be, so apologies for that. Searching for JWT gave me loads of forum options to see where others had posted.

I've read up on JWT and in principle it seems reasonably straightforward. The problem I have is that I cannot find decent examples of what I am trying to do. First of all, I am writing a C# application. It is the client. My customer has a web API where I used to send data to it, and they have now asked that I modify the code in my client to connect to their server using JWT. They have given me a URL and if I use Postman and hit that URL, add in the supplied user name and password, I get back this:

{
"AuthToken": "Bearer eyJhbGciOiJSUzI1NiJ9.eyXXXXXXXXXXT04iOiJGT1JXQVJESU5HLUFMTCIsIlVTRVJfREFUQSI6IntcInVzZXJJRFwiOlwiVEFSQUtcIixcIm93bmVySWRcIjpcIkhRXCIsXCJhdXRoT3duZXJJZHNcIjpcIkRQTy1VUyxEUE8tQk9TLEhRLEZYVCxIRUxFTjAsSlBOLFNHLFhQTy1CT1MsRlJBLExRQ09NLVNIQSxNQU4sUEFSLFhQT0wsXXXXXXXXXXxRQ09NLUxBWCxNSUEsU0hBMSxZQ0hDT00tRVBBLEpBTSxLT0IsU0lOLFVTQSxYUE8tVVMsU0hBLEJPUyxDTixDVFJZR0IsQ1RSWUlULEVVLExRQ09NLVNJTixCSlMsRE9SLEtJTixMQVgsQVRMLENUUllOTCxHT0EsR1lIX0NPTSxMT04sRFBPLU1JQSxEUE8tQVRMLERQTy1MQVgsRFBPLVNHLE5ZQyxEUE9MLERQTy1TSU4sRFBPLUNOLERQTy1TSEFcIixcImRic2NoZW1hXCI6XCJcIixcInNjb3BlXCI6XCJGT1JXQVJESU5HLUFMTFwifSIsIlRPS0VOX1VTRVJfSUQiOiJUQVJBSyIsImlzcyI6IkZPUldBUkRJTkciLCJzdWIiOiJGT1JXQVJESU5HLUFMTCIsImlhdCI6MTU2OTMzNDQ3MywiZXhwIjoxNTY5MzM0NTkzfQ.Bna0lv_6wjscunGUHFeW4JW-aY-iE1bliA1tmJwoWvRvzyOVvGb9n9U2r4IomoXOAJmOk9YX41j5eBlypOYYPo4d5xKBII0S2rPmGsPAW2fltMCbiRVJjZNNboT0b4vs8qKpYqOwPOpuvehiB54WZ5BlkmYfRbg0quw9oftExNxVYROUV2fHWpawW3-CjREcHEmukqwDO5KXwY4GGH8KNwjAkg2f1SyUwkawUxS85bUNV_4_4kJmq8Aj0_eB-uF3eJ82Ng12eK3PdHuXzkVWY_wE1F9thEdQk0aPWeulpSlPx5ITAQ20cc1CNzqZGdFib82gm-0UHE5IWwcFJbJscA",
"Expires": "2019-09-24T14:16:33.178Z"
}

So, I know the supplied details work. What I am trying to do now is work out how I am supposed to use that within my client application. If there is an error (let's say the supplied details aren't right, then I get this response:

{
"Message": [
{
"Type": "ERROR",
"ErrorCode": "1005",
"Text": "Unauthorized Access : Please check token/user credentials"
}
]
}


So, at the moment, I have not installed any JWT Nuget packages as there are loads and I cannot find any reason to choose one over the other. All examples I read on the net are about how to write the server side bit and nothing that I can find that shows how to be the consumer.

My client application is run via a Windows scheduled task. It runs twice a day. All it does is pull data from a Sage accounts system and constructs a bunch of objects which are then serialised into XML and sent to the customer. All that bit works and I can still get the serialised XML string, but I just don't know how to connect to the server using JWT and send it and manage the responses whether it is an error or success. Any pointers from anyone about how to post to a web service that uses JWT?


Thanks

Continue reading...
 
Back
Top