Credential objects can be used in actions which require the user to provide a username, password and optionally a host name, to connect to a service. By using credentials objects, actions can be written to connect to arbitrary web services without hard coding credentials into the action.

When an authorize() call is made on a credential object for the first time, the user is prompted to enter their credentials, then Drafts stores those for later use. When the action is used again, there will be no prompt required and the stored credentials will be used.

Credentials objects have unique identifiers, and a single set of user credentials can be used across actions by using the same identifier.

The user can delete those credentials at any time by visiting Settings > Credentials and tapping the "Forget" button on a service.

Example

let credential = Credential.create("My Service", "Description of the service to  * appear in user prompt.");

credential.addTextField("username", "Username");
credential.addPasswordField("password", "Password");

credential.authorize();

let http = HTTP.create();
let response = http.request({
"url": "http://myurl.com/api",
"username": credential.getValue("username"),
"password": credential.getValue("password"),
"method": "POST",
"data": {
"key":"value"
},
"headers": {
"HeaderName": "HeaderValue"
}
});

Hierarchy

  • Credential

Constructors

  • Create new instance.

    Parameters

    • identifier: string

      Unique identifier for the credentials

    • Optional description: string

      Optional description

    Returns Credential

Methods

  • Add a secure entry text field for data entry.

    Parameters

    • key: string

      used to retrieve the value

    • label: string

      label is displayed to the user

    Returns void

  • Add a text field for data entry.

    Parameters

    • key: string

      used to retrieve the value

    • label: string

      label is displayed to the user

    Returns void

  • Add a text field for configured for URL data entry.

    Parameters

    • key: string

      used to retrieve the value

    • label: string

      label is displayed to the user

    Returns void

  • Call this function after configuring, but before using host, username or password properties of a credential. If the credential object has not be previous authorized, the user will be prompted to enter their credentials before continuing. If the user has previously been prompt, this method will load previously provided information.

    Returns boolean

  • Deletes the credentials provided by the user. This is the same as the user visiting settings and tapping "Forget" for the credentials.

    Returns void

  • Get the value the user stored for the key, as defined in a call to add the field.

    Parameters

    • key: string

    Returns string

  • Create a credential object with the specified identifier and description. Identifiers should be unique, such that any two calls from different actions with the same identifier will return the same credentials

    Parameters

    • identifier: string

      Unique identifier for the credentials

    • Optional description: string

      Optional description

    Returns Credential

  • Create credential already configured with host url, username and password fields.

    Parameters

    • identifier: string

      Unique identifier for the credentials

    • description: string

      Optional description

    Returns Credential

  • Create credential already configured with username and password fields.

    Parameters

    • identifier: string

      Unique identifier for the credentials

    • description: string

      Optional description

    Returns Credential

Generated using TypeDoc