authenticate
Specify an HTTP authentication scheme and its information before working with web services.
Name | Description | Type | Modifier |
---|---|---|---|
schema | HTTP authentication scheme Possible values:
| Value Set | Basic, OAuth 2, Digest |
value | HTTP authentication information (see ). | String | None |
None
This action may be used within the following project items: test modules and user-defined actions.
Example 1 - Basic authentication scheme
Suppose that you'd like to test the a given API based on the following information:
- Authentication scheme: Basic authentication
- Web service under test: http://192.168.190.212:8091/api/authenticate
- Username: john.doe
- Password: R6z,nUjeH];3L4r:
name value
local variable username john.doe
local variable password R6z,nUjeH];3L4r:
local variable uri http://192.168.190.212:8091/api/authenticate
 
schema value
authenticate basic # username& ":" & password
 
create http request
 
uri method timeout variable expected code
send http request # uri GET 200 >>response 200
 
response status header body
parse http response # response >>status >>header >>body
Example 2 - OAuth 2.0 authentication scheme
Suppose that you'd like to test a given Gmail API to get all messages based on the following information:
- Authentication scheme: OAuth 2.0
- Web service under test: Users.messages: get
- Access token:
ya29.Ci-fA76X0cjJXa2Lx0RM-fRyAQ6-6pboEX-iuT7PR-yYV6D-Rfbos7bs151wiL-O7w
Tip:For Google APIs in order to retrieve the access token for OAuth 2.0, read here.
name value
local variable uri https://www.googleapis.com/gmail/v1/users/me/messages
local variable access token ya29.Ci-fA76X0cjJXa2Lx0RM-fRyAQ6-6pboEX-iuT7PR-yYV6D-Rfbos7bs151wiL-O7w
 
schema value
authenticate oauth 2 # access token
 
create http request
 
key value
add http header Content-Type application/json
 
uri method timeout variable expected code
send http request # uri GET 200 >>response 200
 
response status header body
parse http response # response >>status >>header >>body
Example 3 - Digest authentication scheme
Suppose that you'd like to test a given API based on the following information:
- Authentication scheme: Digest authentication
- Web service under test: http://192.168.167.29:8081/api/authenticate
- Username: john.doe
- Password: 123
name value
local variable username john.doe
local variable password 123
local variable uri http://192.168.167.29:8081/api/authenticate
 
schema value
authenticate digest # username& ":" & password
 
uri method variable timeout expected code
send http request # uri GET >>response 100 200
 
response status header body
parse http response # response >>status >>header >>body
- You are required to declare this built-in action before the authentication is started. Additionally, this built-in action can also be declared after or before the declaration of create http request.
- value argument: Depends on which authentication scheme is selected, there are different ways to provide HTTP authentication information.
- For Basic HTTP authentication scheme: Specify username and password to authenticate with the service you are using. Follow this format
userid:password
.Tip:You can either input a plain text string or a base64url encoded string. To encode a text string into a base64url encoded string, you can use the Online Base64URL encoder tool.
For example: username is John and password is Doe.- Plain text string:
John:Doe
- Base64url encoded string:
Sm9objpEb2U
- Plain text string:
- For OAuth 2.0 scheme: Specifying an access token which is required to access OAuth protected resources. For example:
ya29.Ci-fA76X0cjJXa2Lx0RM-fRyAQ6-6pboEX-iuT7PR-yYV6D-Rfbos7bs151wiL-O7w
- For Digest authentication scheme: Specify two fields including username and password to authenticate with the service you are using. Follow this format username:password.
- For Basic HTTP authentication scheme: Specify username and password to authenticate with the service you are using. Follow this format
- This action supports the <ignore> modifier. If the string
<ignore>
is present as the value of any of the arguments, or any argument contains an expression that evaluates to<ignore>
, the action is skipped during execution.