Skip to content
Open dashboard (opens in a new tab)

Authentication

Generate a login script

NightVision can write a login script for you. You give it a web application, a username and a password. It finds the login form, signs in once, and saves the steps as the same kind of Playwright script a recorded login produces. There is no browser to open and no CLI to install.

You start a generation with one API request. The result is an ordinary recorded login on the Authentications page.

Generate Record
The login is a username and password form The login goes through single sign-on, or has steps a form does not describe
You are setting up many applications and want no manual step for each You want to walk the login yourself and see each step
The account has no second factor The login asks for a one-time code, a CAPTCHA or a device check
NightVision Cloud can reach the application The application is only reachable from your network

If generation cannot finish a login, record it. A recorded login handles every case generation does.

Field Notes
target The id of a web application. The API calls an application a target. Copy the Application ID from the application’s Setup tab
username Up to 1,000 characters. Used exactly as sent, including any spaces
password Up to 1,000 characters. Used exactly as sent
name Optional. Defaults to the application’s name followed by -generated-login, with -2, -3 and so on when that name is taken
description Optional, up to 500 characters

Use a dedicated test account. The username and password cannot contain {{ or }}.

You need permission to manage authentications in the application’s project.

  1. It creates a recorded login in the application’s project with no script yet, in the state GENERATING.
  2. It opens the application, finds the login form, and signs in with the username and password.
  3. It writes the steps as a Playwright script and replays it to confirm the script signs in.
  4. When the script is ready, the authentication becomes READY and NightVision assigns it to the application, replacing the authentication the application had.

One generation runs per application at a time. Until an authentication is READY, it cannot be used for a scan, assigned to an application or duplicated.

Once it is ready it behaves like any recorded login. You can read the script on its Script and settings tab, edit it, re-record it, duplicate it and run a login check against it.

The script never contains the username or the password. It holds two placeholders, {{0}} for the username and {{1}} for the password:

page.get_by_label("Email").fill("{{0}}")
page.get_by_label("Password").fill("{{1}}")
page.get_by_role("button", name="Sign in").click()

The values are stored encrypted, apart from the script, the same way a recorded login’s typed values are. They are filled in only when a scan replays the login. No API response and no screen returns them.

A generation that cannot produce a working script ends as FAILED, with a category in generation_failure_category and a sentence in generation_detail. The same reason is written as a comment in place of the script, so you also see it on the authentication’s Script and settings tab.

Category What it means What to do
INSUFFICIENT_CONFIG The application did not let NightVision in with what you provided: the credentials were rejected, a second factor was asked for, the login was blocked, or the application did not show a signed-in page after the username and password were submitted Check the username and password. If the account has a second factor, record the login and configure MFA
TOOL_LIMITATION NightVision could not complete the login by itself: it found no login form, could not get as far as submitting the username and password, or the generated script did not replay Record the login

A generation that has reported nothing after 25 minutes reads as FAILED with TOOL_LIMITATION.

A failed authentication cannot be used for scans. You have two ways forward:

  • Start a new generation with corrected values.
  • Save a script of your own on the failed authentication, by editing it or re-recording. It then becomes an ordinary recorded login.

Start a generation:

Terminal window
curl -X POST https://api.nightviz.ai/api/v1/credentials/generate-script/ \
-H "Authorization: Token $NIGHTVISION_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"target": "<application id>",
"username": "scan-user@example.com",
"password": "<password>"
}'

The answer is 202 Accepted with the new authentication. Its generation_status is GENERATING.

Poll the authentication until the status changes:

Terminal window
curl https://api.nightviz.ai/api/v1/credentials/<authentication id>/ \
-H "Authorization: Token $NIGHTVISION_TOKEN"
generation_status Meaning
GENERATING Still working
READY The script is saved and the authentication is assigned to the application
FAILED See generation_failure_category and generation_detail
null An authentication that was not generated

Other answers from the generate request:

Status Meaning
400 A field is missing or invalid, or the application is not a web application
409 A login script is already being generated for this application. Nothing was saved
503 The generator could not be started. Nothing was saved. Try again

See the API overview for tokens.