Symfony NelmioApiDocBundle中的Oauth2授权

Symfony NelmioApiDocBundle中的Oauth2授权,symfony,symfony-3.4,nelmioapidocbundle,Symfony,Symfony 3.4,Nelmioapidocbundle,我试图将NelmioApiDocBundle用于Symfony 3.4项目API文档,同时也试图从项目API访问的OAuth 2授权开始 到目前为止,我已经了解了如何让FOSOAuthServerBundle工作。到目前为止我能做到 1.)使用命令行命令创建客户端: php bin/console fos:oauth服务器:创建客户端--重定向uri=“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

我试图将NelmioApiDocBundle用于Symfony 3.4项目API文档,同时也试图从项目API访问的OAuth 2授权开始

到目前为止,我已经了解了如何让FOSOAuthServerBundle工作。到目前为止我能做到 1.)使用命令行命令创建客户端:

php bin/console fos:oauth服务器:创建客户端--重定向uri=“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

2.)我还可以通过访问服务器上的此url手动获取访问令牌

3.)通过在GET参数中包含令牌,我可以使用令牌访问需要OAuth访问的Symfony项目区域

然而,在NelmioApiDocBundle授权中,我无法完成这项工作。以下是一个屏幕截图:

如果输入我的客户机id和密钥,我将按预期进入登录页面。我可以输入我的登录信息,并按预期进入“批准”或“拒绝”页面。此时,如果单击“批准”或“拒绝”,它将尝试使用的“重定向uri”。无论我做什么,我都无法更改重定向URI


如何获得正确的重定向URI?

好的,这实际上很容易修复。您需要添加一行:

oauth2RedirectUrl: 'URLhere',
到位于web/bundles/nelmioapidoc中的文件init-swagger-ui.js(Symfony 3.4)/

最终的文件看起来像这样:

window.onload = () => {
  const data = JSON.parse(document.getElementById('swagger-data').innerText);
  const ui = SwaggerUIBundle({
      oauth2RedirectUrl: 'URLhere',
    spec: data.spec,
    dom_id: '#swagger-ui',
    validatorUrl: null,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: 'StandaloneLayout'
  });

  window.ui = ui;
};

此外,您可能还想从Swagger项目下载该文件,以包含在实际重定向中。

好的,这实际上很容易修复。您需要添加一行:

oauth2RedirectUrl: 'URLhere',
到位于web/bundles/nelmioapidoc中的文件init-swagger-ui.js(Symfony 3.4)/

最终的文件看起来像这样:

window.onload = () => {
  const data = JSON.parse(document.getElementById('swagger-data').innerText);
  const ui = SwaggerUIBundle({
      oauth2RedirectUrl: 'URLhere',
    spec: data.spec,
    dom_id: '#swagger-ui',
    validatorUrl: null,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: 'StandaloneLayout'
  });

  window.ui = ui;
};
此外,您可能还想从Swagger项目下载该文件,以包括实际重定向