Skip to main content

Plugin call OpenAPI

Suitable EnviromentSaaS
Private Deployment

Requirements

ONES
v3.14.138+,v6.2.4+

Overview

This is a method for accessing ONES OpenAPI in a plugin. This method uses the FetchAsUser and FetchAsAdmin APIs defined by the @ones-op/fetch package, it automatic completion of OAuth2 authorization to obtain a token, and automatically re-acquire the token after it expires.

Usage

Step 1: Installation dependency

Enter the /web or /backend directory of the plugin project, and execute the following command for dependent installation:

npm i @ones-op/fetch

Step 2: Configure the authorization information

Configuration file: config/plugin.yaml

Example one: Use user and super admin to call ONES OpenAPI

config/plugin.yaml
oauth:
type:
- user
- admin
scope:
- read:project:project
- write:project:project

Accessing as a user:

config/plugin.yaml
oauth:
type:
- user

Accessing as an organizational admin:

config/plugin.yaml
oauth:
type:
- admin
info
  1. We recommended to use the user type for plugin front-end and the admin type for plugin back-end to access OpenAPI.
  2. The admin type only can use for plugin back-end.
  3. The OpenAPI scope that the plugin allows access to is defined through the scope parameter. For more parameter values, please Refer to OAuth 2.0 Scopes.

Step 3: Accessing OpenAPI

API: FetchAsUser / FetchAsAdmin

For specific usage, please refer to @ones-op/fetch. After installing and enabling (authorizing) the plugin, it can access ONES OpenAPI.