titiyoyo
titiyoyo

Reputation: 942

Mac PAW app - get form authentication token

I'm trying to authenticate automatically using Paw and to do this I need to

  1. make a request to the login page
  2. parse the html response to get an auth token from a login form
  3. send the authentication request

but I don't know how to do that...

Anyone has an idea?

Thanks

Upvotes: 4

Views: 336

Answers (1)

Matthaus Woolard
Matthaus Woolard

Reputation: 2408

In paw first set up the request to the login page. Then in a second request you can asses the response body of the first request: we can use a regex filter on the raw response of another request.

create a custom dynamic value: Adding a custom dynamic value

then use the code below to set the custom dynamic value.

function evaluate(context){
	// Set up your regex to extract the token
	var re = /<h2>([^<]+)<\/h2>/;
	
	// Replace the 'Login page' with your request name 
	var request = context.getRequestByName('Login page')
	var lastExchange = request.getLastExchange()
	var body =  lastExchange.responseBody
	
	var m = re.exec(body)
	return m[1]
};

Upvotes: 3

Related Questions