How to handle when there is a separate Basic Auth endpoint and api endpoint for each environment
How to handle when there is a separate Basic Auth endpoint that returns a JWT and api endpoint for each environment
Here is the use case:
1. There are multiple environments and each environment has a tenant.
Example <env1><tenant1>, <env1><tenant2>, env2><tenant1>
2. Each environment has an auth endpoint and api endpoint. Example:
Auth endpoint: https://<env1><tenant1>auth.com
API endponts: https://<env1><tenant1>api.com/api
3. The auth endpoint is Basic Authentication and requires a username with this structure:
username: <env1><tenant1>/username
password: ***********
4. The auth endpoint returns a JWT token, in the following response
5. The access_token must be parsed from the response and then included in the Header of the api requests.
In it's simplest form, I was able to accomplish this by using:
- No Environment
- Hardcoding the Auth endpoint
- Hardcoding the api endpoint
- Getting the token in an auth request 'Login' test step
- Grabbing the token and using it in the next step by placing this in the header: Bearer ${Login#Response#$['access_token']}
But I need to be able to automate this so that I can switch environments at run time.
I've done a lot of research and haven't found many suggestions besides 'create a script'. I'm hoping there are other ways, but if I have to go the script route, it's not the end of the world. Has anyone else encountered a similar scenario? What is the easier strategy for handling a scenario like this? I appreciate any advice!
NOTE: I can't seem to use the built in Authentication Manger in ReadyAPI because the Basic Authentication returns a response that must be parsed. Unless there is a way around this that I don't know about 🙂
srixon ,
given the details you gave us above I would suggest the following solution:
- Set your tenant as the project level property, e.g. tenant
- Define environment specific stuff within Environment configuration
- Define two APIs:
- one for authorization API
- second for your target API
- In the endpoints use project-level tenant property (e.g. ${#Project#tenant}) to parametrize the endpoints
- Grab the token from the authorization response and save it to another project-level property
- Define two APIs:
When executing the testrunner, use parameters:
-E to set the environment
-P to set the tenant (project level variable)
Best regards,
Karel