我正在编写一个带有ajax身份验证的ajax应用程序,现在我开始在silex中使用symfony安全组件来处理身份验证/授权.
使用简单配置进行简单测试,我通过防火墙进入受保护区域,我得到的响应是重定向到/ login页面,但我在应用程序中需要的是401响应,可能有其他信息(在标题或关于如何登录的json body.
$app['security.firewalls'] = [
'api' => [
'pattern' => '^/api',
'logout' => ['logout_path'=>'/auth/logout'],
'users' => $app->share(function(Application $app) {
return new MyUserProvider();
})
]
];
编辑:我有一个提示,但我不知道如何使用它.使用AuthenticationEntryPointInterface实现入口点我可以告诉api如何回答未经身份验证的请求并向用户提供身份验证所需的指令.这可能是我的401响应登录说明.
解决方法:
您需要的是AuthenticationEntryPoint处理程序.
简单的例子:
class AuthenticationEntryPoint implements AuthenticationEntryPointInterface {
/**
* Starts the authentication scheme.
*
* @param Requ