Requesting a token


(Tim Trodd) #1

Matrix Version: 5.5.3.0

Hello,

I am currently testing out an API of a system we would like to use in the future.

To grab the token (bearer), we use a post request with this in the body(x-www-form-urlencoded) :

username:xxx
password:xxx
grant_type:password

With the post to a url www.abc.com/token

This supplies us back with a token which is valid for 24hs.

Using postman I can easily do the above. Is there anything in matrix to be able to:

a) retrieve the token with just the above details?
b) refresh the token every 24 hours automatically?

Cheers,

Tim


(Tim Trodd) #2

I suppose I could retrieve the token using another REST resourse asset, then grab the contents of that asset within the other rest asset. Not sure if there is a better way?


(Tim Trodd) #3

Ignore this thread. I did the above:

  1. REST asset to retrieve the token.
  2. used the js area in the REST to grab the token value and print it to the page
  3. used %globals_asset_contents_raw:xxx% in the other REST asset that actually grabs the real content in the post body.
  4. seems to all work ok and grabs a new token each time which also solves my part b in the original post.

Cheers

Tim


(Tbaatar) #4

Might want to edit the xxx dot com link. Not work friendly at all :scream_cat:


(Tim Trodd) #5

Hahah definitely didn’t think that one through! Changed it!


(Bart Banda) #6

What API are you connecting to? Is it OAuth2 based at all? Could you use the OAuth2 or other OAuth token assets to manage the token refresh for you?

haha :rofl: