Jump to content
Stuart Clennett

MarsToken.SaveToFile / LoadFromFile

Recommended Posts

Hi,

 

I'm trying to save a JWT token to a file between program runs.  I have a console app that runs on a short schedule and I want to prevent having to authenticate each time.

 

I am using MarsClientToken SaveToStream / LoadFromStream to get the json token data into and out of a temp file.   The contents of the temp file look fine & contain the json I would expect, i.e. the "Token" and each token property (the expired date is always +24hrs )

 

When the token data is loaded from the file, IsVerified = True, isExpired = false, and Authenticated = True, but I am getting 403 forbidden when I make my api calls.    Logging in with username/password works fine of course.

 

Is there something I am missing ? 

 

Thanks

 

Share this post


Link to post

Hi, hard to say without looking at the code but I guess it is because of the TMARSClient.AuthEndorsement value.

By default MARS uses cookies to endorse the token in the requests. But if you are loading the token from file, it is quite probable the client does not have the cookie set.

 

MARS actually supports two ways to endorse the token in the request: cookie and the Authorization header. If you set the client AuthEndorsement property to AuthorizationBearer, does it works?

 

I've built a simple example (server and client) as an example:

 

https://www.dropbox.com/s/zu0ovdhj1g88md9/MyConsole.zip?dl=0

 

Just run the MyConsoleServerApplication and then the MyConsole.

 

Let me know if everything is fine.

 

Sincerely,

Andrea

Share this post


Link to post

HI Andrea,

 

Yes, that was it, I had AuthEndorsement set to cookie.

 

So sorry, I thought I had checked that but clearly not.

 

Kind regards

Share this post


Link to post
6 hours ago, Stuart Clennett said:

HI Andrea,

Yes, that was it, I had AuthEndorsement set to cookie.

So sorry, I thought I had checked that but clearly not.

 

No problem at all!

I am investigating if it would be possible to force cookies of the client when loading the token from file/stream. IIRC it was not easy to do with one of the two http client libraries currently available (Indy and NetHttpClient).

 

Sincerely,

Andrea

 

Share this post


Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×