我试图在Symfony 3.4ProjectsAPI文档中使用NelmioApiDocBundle,同时还试图了解OAuth 2对项目API访问的授权。
到目前为止,我一直在跟踪本教程如何使FOSOAuthServerBundle工作。到目前为止我还能做到。)使用命令行命令创建客户端:
php /console fos:oauth-server:create-client -redirect uri=“___”-授予-type=“authorization_code”-授予-type=“refresh_token”-授予-类型=“令牌”-授予-类型=“client_credentials”
2.)我还可以通过访问服务器上的这个url来手动获取访问令牌。
凭据
3.)通过在GET参数中包含令牌,我可以使用令牌来访问需要OAuth访问的Symfony项目的区域
但是,在NelmioApiDocBundle授权中,我无法完成这一任务。这是一个截图:

如果输入我的client_id和秘密密钥,它会像预期的那样带我到登录页面。我可以输入我的登录信息,并在带我到批准或拒绝页面,如预期。此时,如果我单击“批准”或“拒绝”,则尝试使用"redirect_uri“的http://localhost:3200/oauth2-redirect.html。无论我做什么,我都不能更改重定向URI。
如何获得正确的重定向URI?
发布于 2018-03-27 17:33:34
好吧,这个其实很容易解决。您需要添加一行:
oauth2RedirectUrl: 'URLhere',文件init-swagger-ui.js,位于web/bundle/nelmioapidoc/ (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项目下载文件oauth2-redirect.html,以便包含实际重定向。
https://stackoverflow.com/questions/49518868
复制相似问题