Authenticate to a ServiceNow instance using OAuth 2.0 with the ServiceNow SDK

  • 릴리스 버전: Australia
  • 업데이트 날짜 2026년 03월 12일
  • 소요 시간: 3분
  • Use OAuth 2.0 authentication to connect to a ServiceNow instance with the ServiceNow SDK.

    시작하기 전에

    To use OAuth 2.0 authentication, your instance must have ServiceNow IDE (version 1.1 or later) installed or have the required XML configuration imported. By default, instances on the Australia release include ServiceNow IDE version 1.1.4 and support using OAuth 2.0 authentication with the ServiceNow SDK.

    Role required: admin

    이 태스크 정보

    This procedure uses the ServiceNow SDK command-line interface (CLI). From a command-line tool, enter now-sdk --help to get information about the available commands and global options. To get additional information about a command and its parameters, enter the command and --help or -h. For example, now-sdk auth --help. For more information about the CLI, see ServiceNow SDK CLI.

    프로시저

    1. Create a local directory for your application.
    2. In Visual Studio Code, open the directory.
    3. From the application directory, open an integrated Terminal window.
    4. Specify the instance to authenticate to with the auth command.
      npx @servicenow/sdk auth --add <instance>
      For example:
      npx @servicenow/sdk auth --add https://myinstance.service-now.com
      주:
      Using the npx command installs the ServiceNow SDK in your application directory instead of globally.
    5. Respond to the following series of prompts.
      Prompt Response
      Type of authentication to use Select oauth.
      Alias for these credentials Enter an alias for your credentials and the instance.

      The alias can be used for authentication with the init, transform, dependencies, and install commands.

      The ServiceNow SDK opens a web browser to authenticate with the instance.
    6. Navigate to the web page that opens and log in to the instance if you aren't currently logged in.
    7. Select Accept to allow the ServiceNow SDK to connect to the instance.
      The page refreshes and includes an authentication code.
    8. Select Copy to copy the authentication code provided.
    9. In the command line, paste the authentication code.

    결과

    The alias and credentials are stored in the device keychain or credential manager on your system and are set as the default credentials.

    다음에 수행할 작업

    Add an application to your local system with the ServiceNow SDK. For more information, see Adding applications with the ServiceNow SDK.