目录

Template File

The template file contains two files required by the customized authentication plugin: CustomAuth.ts and tsconfig.json.

Plugin Template CustomAuth.ts

import {AuthPlugin} from '../libs/plugins/auth/AuthPlugin';  // This default reference address is used if the CustomAuth.ts plugin file is stored in the default location (the plugins folder in the root directory where ohpm-repo is decompressed).
export class CustomAuth implements AuthPlugin {
  /**
* Obtaining user information, which is returned based on the value of accessToken, including the user ID, user name, organization to which the user belongs, and organization created by the user.
   * @param accessToken Access token of the user
   */
  async auth(accessToken: string): Promise<{
    id: string;                         // User ID, which must be unique.
    name: string;                       // User name, which must be unique.
    belongGroupList: Array<string>;     // Organization to which the user belongs. The user has the permission to publish packages for the specified organization.
    groupAdminList: Array<string>;      // Organization managed by the user. The user has the permission to delete packages from a specified organization.
  }> {
    let id: string, name: string, belongGroupList: Array<string>, groupAdminList: Array<string>;
    return {id, name, belongGroupList, groupAdminList};
  }

  /**
   * Obtaining user information, which is returned based on the value of the read-only accessToken, including the user ID, user name, organization to which the user belongs, and organization created by the user.
   * @param accessToken: Read-only access token of the user
   */
  async authWithReadOnly(accessToken: string): Promise<{
    id: string;                         // User ID, which must be unique.
    name: string;                       // User name, which must be unique.
    belongGroupList: Array<string>;     // Organization to which the user belongs. The user has the permission to publish packages for the specified organization.
    groupAdminList: Array<string>;      // Organization managed by the user. The user has the permission to delete packages from a specified organization.
  }> {
    let id: string, name: string, belongGroupList: Array<string>, groupAdminList: Array<string>;
    return {id, name, belongGroupList, groupAdminList};
  }

  /**
   * Returning the user name based on the user ID.
   * @param id indicates the user ID.
   */
  async getUserInfo(id: string): Promise<string> {
    let name: string;
    return name;
  }
}

Configuration File tsconfig.json for TS Compilation

// The tsconfig.json file specifies the compilation options and the files required for the compilation in the root directory. The custom plugin file (.ts) is compiled into a .js file.
{
  "include": [
    "plugins/*" // Location of the plugin file
  ],
  "compilerOptions": {
    "target": "es2016",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "module": "commonjs",
    "rootDir": "./plugins",
    "typeRoots": [
      "./node_modules/@types"
    ],
    "types": [
      "node",
    ],
    "resolveJsonModule": true,
    "outDir": "./plugins/outDir",   // Output location of the file after the compilation
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "alwaysStrict": true,
    "strict": false,
    "noImplicitReturns": true,
    "skipLibCheck": true
  }
}