Function signToken

  • Given a State Backed key id and secret, end-user claims, and signing options, return a Promise for a signed JWT suitable for sending in the authorization header of requests to State Backed.

    The end-user claims should include a sub claim with the end-user's unique id and may include any other data that your machines' allowRead and allowWrite authorization functions need.

    It is best practice to set the issuer in your signing options to your domain and set either expires.at or expires.in to a reasonable value, matching your session duration.

    Parameters

    • key: Key

      The State Backed key id and secret to use for signing. You can generate one by running smply keys create. Check the Getting Started guide at https://docs.statebacked.dev/ for more information.

    • payload: {
          sub?: string;
          [key: string]: any;
      }

      The end-user claims to include in the JWT. Should include a sub claim with the end-user's id.

      • [key: string]: any
      • Optional sub?: string
    • options: SigningOptions

      Options for signing the JWT. Set issuer to your domain and provide either expires.at or expires.in to set the expiration time. expires.in should be a string like "7d" or "30m". expires.at can be a Date or seconds since epoch. expires.at is used if both are provided.

    Returns Promise<string>

    A Promise for a signed JWT.

Generated using TypeDoc