Integrate Security Audit with Visual Studio Code

You can integrate API Security Audit with Microsoft Visual Studio Code (VS Code) through the extension OpenAPI (Swagger) Editor.

For more details on VS Code integration, see VS Code integration.

Create an IDE token

The extension uses a token to authenticate to 42Crunch Platform, so on the first time, you must provide one that the extension can use. If you already have an account in 42Crunch Platform or want to create one, you can create an IDE token and use that one.

  1. Log in or sign up to 42Crunch Platform.
  2. Click Create a new IDE token on the landing page.
  3. Copy the value of your IDE token and store it securely, you will need it to configure your IDE extension.

If you do not have 42Crunch Platform account and do not want to create one to take advantage of the more advanced integration options, you can also provide your email address when configuring the IDE extension.

Update your token

If you want to use a new IDE token — or change to using IDE tokens to unlock more integration features — you can reconfigure the token that the IDE extension uses.

  1. Create an IDE token, and remember to copy the token value and store it securely before closing the configuration window. For security reasons you cannot view the token value later.
  2. In VS Code, open the command palette, and select the command 42Crunch: Update platform credentials.
  3. Enter the URL your organization uses to access 42Crunch Platform. For most users, this is https://platform.42crunch.com. If you are not sure what your platform URL is, contact our support.
  4. Enter the value of the new IDE token.

Your IDE will now use the new token to authenticate to 42Crunch Platform.

Configure VS Code

You can find OpenAPI (Swagger) Editor on the VS Code Marketplace.

  1. Install OpenAPI (Swagger) Editor extension to your VS Code editor.
  2. Open the API you want in VS Code in .json or .yaml format.
  3. To run Security Audit from VS Code, click the 42C button at the top edge of the editor.

    On the first time, you must provide a token that the extension can use to authenticate to 42Crunch Platform:

    • If you have created an IDE token, select the button for the existing user, and enter the token value you copied and the URL your organization uses to access 42Crunch Platform. For most users, this is https://platform.42crunch.com. If you are not sure what your platform URL is, contact our support.
    • If you do not want to use an IDE token, select the button for new user and enter your email address so we can mail you a token you can use instead.

    Configuring the token is done only once, on subsequent audits you just click the button.

    Security Audit checks your API definition and provides audit score and report on the found issues in the editor just like in the platform. The elements containing issues are also marked in your code. For more details, see Audit report in VS Code.

    An example screenshot of an audited API definition in VS Code.

  4. Click the icons in the status bar to open the Problems panel, scroll through the issue titles, and click on an issue to jump to view it inline in your API definition. The issues are ordered from most to least severe, so it is easy for fix the worst offenders first. Recommendations are not listed in the Problems panel.
  5. Hover on an element marked in your code to see the list of issues in that spot, and click on the list to filter the text panel to show only these issues.
  6. Edit your API definition to fix found issues, save your changes, and click the 42C button to re-run the audit.

For more details on how OpenAPI (Swagger) Editor helps in creating and editing OpenAPI definitions, see the instructions in the VS Code Marketplace.

Load audit report from a file

You can open an audit report that has been exported from 42Crunch Platform to view it in VS Code without auditing the API again. This way, you can work on fixing audit issues from an audit report that, for example, someone in a different team shared with you.

  1. Obtain the audit report (either from someone else, or download it yourself) from 42Crunch Platform as a JSON file. See Export audit report.
  2. Open the API definition that the audit report was for in VS Code, either as .json or .yaml.
  3. Go to the command palette in VS Code, and select the command 42Crunch: Load Security Audit report from file.

VS Code loads the exported report from the file and you can now navigate it just as if the audit had been run in VS Code.

If you fix an issue and run Security Audit in VS Code to verify your fix, the audit report your loaded from the file is replaced by the report that the VS Code extension generated.

The exported audit report is a static file: if you reload the exported report file again after fixing an issue in your API, the report still contains the details of that issue and the place you already fixed is highlighted in the editor.

View API collections in the IDE

In addition to running Security Audit, you can also view and manage API collections available to you in 42Crunch Platform directly in the IDE. The IDE extension uses IDE tokens to access and authenticate to 42Crunch Platform. You can create IDE tokens in 42Crunch Platform, either on the landing page or in your account settings.

Creating IDE tokens requires a user account in 42Crunch Platform. If you have so far just used the token that was mailed to you when you first run Security Audit in the IDE, you must sign up for an account before you can configure the integration for viewing the APIs and API collections in your IDE.

  1. If you have not yet done so, change the IDE to use IDE tokens to authenticate to 42Crunch Platform. See Update your token. The IDE extension can now read the API collections available to you and APIs in them when you click the 42C icon in the activity bar.

    The screenshot shows an example of an API in the API collection browser in VS Code.

  2. To open the API definition in the IDE, click OpenAPI definition. To view the audit report, click Security Audit.
  3. To open the API definition in 42Crunch Platform, rename it, or delete it, right-click on the API, and select the action you want.

    Deleting an API permanently removes it from 42Crunch Platform. This action cannot be undone.