Class RequestAuth


public class RequestAuth extends CollectionElement
Postman SDK analog: RequestAuth. Class encapsulating the "auth" property of a Collection or RequestBody. Collections and requests can each have a single auth property, which consists of a type (e.g., 'oauth1') and an array of parameters for that authentication type. For example, oauth2 looks like:
 auth": {
        "type": "oauth2",
        "oauth2": [
            {
                "key": "grant_type",
                "value": "authorization_code",
                "type": "string"
            },
            {
                "key": "tokenName",
                "value": "Oauth2TokenName",
                "type": "string"
            },
            {
                "key": "tokenType",
                "value": "",
                "type": "string"
            },
            {
                "key": "accessToken",
                "value": "oauth2Token",
                "type": "string"
            },
            {
                "key": "addTokenTo",
                "value": "header",
                "type": "string"
            }
        ]
    }
    
Properties are stored as instances of Property
  • Constructor Details

    • RequestAuth

      public RequestAuth()
      Default constructor. Resulting auth has no type or any other properties initialized.
    • RequestAuth

      public RequestAuth(String type)
      Conveninence constructor to initialize an Auth object with the specified type as String.
      Parameters:
      type - The underlying type property of the new Auth object, as a String, e.g., "oauth1"
    • RequestAuth

      public RequestAuth(enumAuthType type)
      Conveninence constructor to initialize an Auth object with the specified type as an enumerated value.
      Parameters:
      type - The underlying type property of the new Auth object, as an enumeration
    • RequestAuth

      public RequestAuth(enumAuthType type, PropertyList<Property> properties)
      Conveninence constructor to initialize an Auth object with a pre-created HashMap of authentication properties
      Parameters:
      type - The underlying type property of the new Auth object, as a String, e.g., "oauth1"
      properties - HashMap<String, Property> containing the properties of this auth element
  • Method Details

    • getKey

      public String getKey()
      Returns the key of this CollectionElement for use in retrieving from arrays, etc.
      Specified by:
      getKey in class CollectionElement
      Returns:
      String
    • getAuthType

      public enumAuthType getAuthType()
      Get the value of the type property of this authentication object. The underlying string value is mapped to an enumerated value.
      Returns:
      enumAuthType The underlying type of this authentication object, e.g., `oauth1`
    • setAuthType

      public void setAuthType(enumAuthType type)
      Set the underlying type property of this auth object using an enumerated value. If the type was previously set to a different value, the properties collection is set to null.
      Parameters:
      type - Enumerated value of the underlying type property
    • getAuthTypeAsString

      public String getAuthTypeAsString()
      Convenience method to return the type property of this auth object as a String
      Returns:
      String The 'type' property of this auth object, e.g., 'oauth1'
    • setProperties

      public void setProperties(PropertyList<Property> properties)
      Set the properties of the Auth object using a pre-created HashMap<String,Property> of properties.
      Parameters:
      properties -
    • getProperties

      public PropertyList<Property> getProperties()
      Return the complete array of properties as a HashMap<String,Property>, or null if none are set.
      Returns:
      HashMap<String, Property>
    • getProperty

      public Property getProperty(String key)
      Retrieve a single element from the array of authentication elements comprising this authentication object.
      Parameters:
      key - A string matching the key of the Auth element to return. Returns null if the specified element is not present.
      Returns:
      Property The auth element, or null if not found.
    • addProperty

      public void addProperty(Property newElement)
      Add a new property, or replace an existing property
      Parameters:
      newElement - The new property
    • addProperty

      public void addProperty(String key, String value)
      Convenience method create and then add a new property to this auth object

      For example, to add the following JSON property to the array of properties:

        {
            "key": "realm",
                  "value": "testoauth@test.com",
                  "type": "string"
        }
       
      authObj.setProperty("realm","somerealm@foo.com") Note that the type property always defaults to "string"
      Parameters:
      key - The key for the new property
      value - The value for the new property