You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.
This is a rather general question for stRest authentication.
Authentication is already covered by your documentation:
requests:login: # will return { authenticated: true }...authNeeded:request:...headers:- name: Authorizationvalue: Bearer <$ login.content.authenticated $> # It's possible to use the status code, headers, and status text from previous calls.
That is exactly what I need, but (for me) it is only the second step.
The way I need to authenticate and where I would need your help to manage this looks like this:
Step 1:
reqest to the webserver -> webserver authenticates the session and returns a cookie
Step 2: <- this is where I fail
request user data with the cookie -> webserver returns the user data AND a token.
Step 3: <- your documented auth approach (works fine)
Further requests can be done with the approach you have already documented. The returned token from step 2 is used.
What I am missing now is how session-handling works with stRest, how to pass a cookie to the server. Do I need to transfer the cookie in chaining or is there a way to use the cookie cache?
I've tested several approaches but unfortunately had no success yet.
In the code example below I am listing some of my most promising approaches:
requests:authenticationRequest: # initial request that authenticates the session and returns a cookie request:url: <$ base_url $>/foo/login method: POST postData: mimeType: application/jsontext:
{
"Username":"username",
"Password":"password"
}
userDataRequest1: # approach 1 -> did not workrequest:url: <$ base_url $>/foo/userdatamethod: GETheaders: - name: Cookievalue: <value of 'Set-Cookie' in response of authenticationRequest>#-------------------------------------------userDataRequest2: # approach 2 -> did not workrequest:url: <$ base_url $>/foo/userdatamethod: GETcookies: - name: <cookie name>value: <cookie value>path: "/"secure: true#-------------------------------------------userDataRequest3: # approach 3 -> did not workrequest:url: <$ base_url $>/foo/userdatamethod: GETheaders:- name: <cookie name>value: <cookie value>furherDataRequest:request:url: <$ base_url $>/foo/barmethod: GET headers:- name: Authorizationvalue: Bearer <$ userDataRequest.content.token $>validate:- jsonpath: content
The response to the first request (authenticationRequest) looks like this:
Well, I found a solution by myself, not perfect but I am glad that I can use strest now.
For anyone who might be interersted in the solution:
The problem was the further usage of set-cookie.
Strest-Client allows to use values from fields of the previous request like this:
loginRequest.headers.set-cookie[0]
That is a valid JSONPath and would show following result:
"ss-id=EXdBqX1EftWlIdbp3bDE; path=/; secure"
Unfortunately this does not work with strest. The response is saved in HAR format and can also be accessed with JSON Syntax. I guess Nunjucks is used for JSON parsing and adds some other behaviour.
Every JSONPath without a "-" is valid and returns the correct result.
In my case "set-cookie" seems to lead to a math operation where cookie is substracted from set (set - cookie). The result is "NaN" (not a number).
A valid JSONPath to avoid this behaviour looks like this:
loginRequest.headers["set-cookie"][0]
Now that I've got the value, I need to cut the resulting string to pass it in the next request with just "name=value" without "path=/; secure".
The only way I found to accomplish this task is to use Nunjucks' 'slice()'.
With 'slice(x, y)' it is possible to cut a string starting from index x to index y. While the length of the cookie value was different over several approaches, the string ending (path=/; secure) remained the same. This approach leads to:
This is a rather general question for stRest authentication.
Authentication is already covered by your documentation:
That is exactly what I need, but (for me) it is only the second step.
The way I need to authenticate and where I would need your help to manage this looks like this:
Step 1:
reqest to the webserver -> webserver authenticates the session and returns a cookie
Step 2: <- this is where I fail
request user data with the cookie -> webserver returns the user data AND a token.
Step 3: <- your documented auth approach (works fine)
Further requests can be done with the approach you have already documented. The returned token from step 2 is used.
What I am missing now is how session-handling works with stRest, how to pass a cookie to the server. Do I need to transfer the cookie in chaining or is there a way to use the cookie cache?
I've tested several approaches but unfortunately had no success yet.
In the code example below I am listing some of my most promising approaches:
The response to the first request (authenticationRequest) looks like this:
Thanks in advance!
The text was updated successfully, but these errors were encountered: