5장. ActiveDocs 및 OAuth


ActiveDocs를 사용하면 사용자가 OAuth 지원 API를 한 곳에서 테스트하고 호출할 수 있습니다.

사전 요구 사항

  • Red Hat Single Sign-On 인스턴스를 설정하고 OpenID Connect 통합을 구성해야 합니다. 설정 방법에 대한 자세한 내용은 OpenID Connect 통합 설명서를 참조하십시오.
  • 또한 ActiveDocs 설정 방법에 대해 잘 알고 있어야 합니다. 3scale에 ActiveDocs 추가OpenAPI 사양 생성 을 참조하십시오.

5.1. 3scale API Management 사양의 클라이언트 인증 정보 및 리소스 소유자 흐름의 예

첫 번째 예제는 3scale 사양에서 OAuth 2.0 클라이언트 인증 정보 흐름을 사용하는 API의 예입니다. 이 API는 모든 경로를 수락하고 요청에 대한 정보를 반환합니다(path, request 매개변수, 헤더 등). echo API는 유효한 액세스 토큰을 통해서만 액세스할 수 있습니다. API 사용자는 액세스 토큰으로 자격 증명(client_idclient_secret)을 교환한 후에만 해당 API를 호출할 수 있습니다.

사용자가 ActiveDocs에서 API를 호출할 수 있으려면 액세스 토큰을 요청해야 합니다. OAuth 권한 부여 서버를 호출하기만 하므로 OAuth 토큰 끝점에 대한 ActiveDocs 사양을 생성할 수 있습니다. 이를 통해 ActiveDocs 내에서 이 끝점에 대한 호출을 허용합니다. 이 경우 클라이언트 인증 정보 흐름의 경우 Swagger JSON 사양은 다음과 같습니다.

{
  "swagger": "2.0",
  "info": {
    "version": "v1",
    "title": "OAuth for Echo API",
    "description": "OAuth2.0 Client Credentails Flow for authentication of our Echo API.",
    "contact": {
      "name": "API Support",
      "url": "http://www.swagger.io/support",
      "email": "support@swagger.io"
    }
  },
  "host": "red-hat-sso-instance.example.com",
  "basePath": "/auth/realms/realm-example/protocol/openid-connect",
  "schemes": [
    "http"
  ],
  "paths": {
    "/token": {
      "post": {
        "description": "This operation returns the access token for the API. You must call this before calling any other endpoints.",
        "operationId": "oauth",
        "parameters": [
          {
            "name": "client_id",
            "description": "Your client id",
            "type": "string",
            "in": "query",
            "required": true
          },
          {
            "name": "client_secret",
            "description": "Your client secret",
            "type": "string",
            "in": "query",
            "required": true
          },
          {
            "name": "grant_type",
            "description": "OAuth2 Grant Type",
            "type": "string",
            "default": "client_credentials",
            "required": true,
            "in": "query",
            "enum": [
                "client_credentials",
                "authorization_code",
                "refresh_token",
                "password"
            ]
          }
        ]
      }
    }
  }
}
Copy to Clipboard

리소스 소유자 OAuth 흐름의 경우 사용자 이름 및 암호 및 액세스 토큰을 발행하는 데 필요한 기타 매개변수에 대한 매개 변수를 추가합니다. 이 클라이언트 자격 증명 흐름 예제의 경우 서명된 사용자에 대한 3scale 값과 grant_type에서 채워질 수 있는 client_idclient_secret 을 전송합니다.

다음으로 echo API의 ActiveDocs 사양에서 client_idclient_secret 대신 access_token 매개변수를 추가합니다.

{
  "swagger": "2.0",
  "info": {
    "version": "v1",
    "title": "Echo API",
    "description": "A simple API that accepts any path and returns information about the request",
    "contact": {
      "name": "API Support",
      "url": "http://www.swagger.io/support",
      "email": "support@swagger.io"
    }
  },
  "host": "echo-api.3scale.net",
  "basePath": "/v1/words",
  "schemes": [
    "http"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/{word}.json": {
      "get": {
        "description": "This operation returns information about the request (path, request parameters, headers, etc.),
        "operationId": "wordsGet",
        "summary": "Returns the path of a given word",
        "parameters": [
          {
            "name": "word",
            "description": "The word related to the path",
            "type": "string",
            "in": "path",
            "required": true
          },
          {
            "name": "access_token",
            "description": "Your access token",
            "type": "string",
            "in": "query",
            "required": true
          }
        ]
      }
    }
  }
}
Copy to Clipboard

그러면 정상적으로 Developer Portal에 ActiveDocs를 포함할 수 있습니다. 이 경우 OAuth 끝점이 먼저 표시되도록 표시되는 순서를 지정하려면 다음과 같습니다.

{% active_docs version: "2.0" services: "oauth" %}





<script type="text/javascript">
  $(function () {
    window.swaggerUi.load(); // <-- loads first swagger-ui

    // do second swagger-ui

    var url = "/swagger/spec/echo-api.json";
    window.anotherSwaggerUi = new SwaggerUi({
      url: url,
      dom_id: "another-swagger-ui-container",
      supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
      onComplete: function(swaggerApi, swaggerUi) {
        $('#another-swagger-ui-container pre code').each(function(i, e) {hljs.highlightBlock(e)});
      },
      onFailure: function(data) {
        log("Unable to Load Echo-API-SwaggerUI");
      },
      docExpansion: "list",
      transport: function(httpClient, obj) {
        log("[swagger-ui]>>> custom transport.");
        return ApiDocsProxy.execute(httpClient, obj);
      }
    });

    window.anotherSwaggerUi.load();

  });
</script>
Copy to Clipboard
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat