Облачная платформаAdvanced

Creating a Custom Authorizer

Эта статья полезна?
Язык статьи: Русский
Показать оригинал
Страница переведена автоматически и может содержать неточности. Рекомендуем сверяться с английской версией.

Scenario

APIG supports custom authentication of both frontend and backend requests.

  • Frontend custom authentication: If you already have an authentication system, you can configure it in a function and then create a custom authorizer by using the function to authenticate API requests.
  • Backend custom authentication: You can create a custom authorizer to authenticate requests for different backend services, eliminating the need to customize APIs for different authentication systems and simplifying API development. You only need to create a function-based custom authorizer in APIG to connect to the backend authentication system.
Note

Custom authentication is implemented using FunctionGraph and not supported if FunctionGraph is unavailable in the selected region.

For details about custom authentication, see the API Gateway Developer Guide.

The following figure shows the process of calling APIs through custom authentication.

Figure 1 Вызов API через пользовательскую аутентификацию


Требования

  • Вы создали функцию в FunctionGraph.
  • У вас есть FunctionGraph Администратор разрешение.

Процедура

  1. Войдите в консоль управления.
  2. Нажмите в верхнем левом углу и выберите API Gateway.
  3. Выберите API Publishing > Custom Authorizers, и нажмите Create Custom Authorizer.
  4. Установите параметры указанные в Таблица 1.

    Таблица 1 Параметры для создания пользовательского авторизатора

    Параметр

    Описание

    Имя

    Имя авторизатора.

    Тип

    • Фронтенд: Аутентифицирует доступ к API.
    • Бэкенд: Аутентифицирует доступ к бэкенд-сервисам.

    URN функции

    Выберите функцию FunctionGraph.

    Источники идентификации

    Параметры запроса для аутентификации. Можно добавить заголовки и строки запроса. Имена заголовков нечувствительны к регистру.

    Этот параметр обязателен только если вы установите Тип к Фронтенд, and Max. Cache Age (s) is greater than 0. When the cache is used, this parameter is used as a search criterion to query authentication results.

    Max. Cache Age (s)

    The time for caching authentication results.

    Value 0 means that authentication results will not be cached. The maximum value is 3600.

    Send Request Body

    Determine whether to send the body of each API request to the authentication function. If you enable this option, the request body will be sent to the authentication function in the same way as the headers and query strings.

    NOTE:

    This option is available only for dedicated API gateways.

    User Data

    Пользовательские параметры запроса, используемые вместе с Источники идентификации когда APIG вызывает функцию.

  5. Нажмите OK.