ws経由でログインできるようにしたいです。
これをcurlが指すようにシミュレートしようとしました/login
が、HTMLなどしか処理しません。ちなみに、私が望まないCSRFが必要です。
したがって、(から) CRSF を無効にするか、login_check
自分でそれを行う方法を見つけたいと思います。
ルートがキャッチされたときに使用される LoginListener をオーバーライドできますか (どこにありますか?) login_check
。
手がかりはありますか?
ws経由でログインできるようにしたいです。
これをcurlが指すようにシミュレートしようとしました/login
が、HTMLなどしか処理しません。ちなみに、私が望まないCSRFが必要です。
したがって、(から) CRSF を無効にするか、login_check
自分でそれを行う方法を見つけたいと思います。
ルートがキャッチされたときに使用される LoginListener をオーバーライドできますか (どこにありますか?) login_check
。
手がかりはありますか?
REST Web サービスに認証と承認を提供する方法は多数ありますが、最も受け入れられているのはOAuthのようです。Facebook、Twitter、Google、Githubなどが利用しています。
Friends Of Symfony の人々は、Symfony2 に OAuth 認証と承認を実装するためのバンドルを持っています: https://github.com/FriendsOfSymfony/FOSOAuthServerBundleと私はこれがあなたが探しているものだと思います。
編集: Oauth の詳細については、Cloudfoundry の人々が数日前に興味深い記事を投稿しました。
使用できる他のオプションについては、単純なものは基本認証です。
firewalls:
main:
pattern: ^/rest
anonymous: ~
form_login: false
provider: fos_user_bundle
http_basic:
realm: "REST Service Realm"
EDIT2:まだこの回答に投票している人がいることがわかったので、この回答を書いている時点ではJWTはまだオプションではありませんでしたが、一部のユースケースではOAuthよりも優れたオプションであることに注意する必要があると思います(例: API が独自のアプリで使用される場合)。Symfony2/3 の適切な JWT 実装へのリンクは次のとおりです: https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Resources/doc/index.md
Web サービスでユーザーを認証するために CURL を使用しないでください。
ResettingController.php (FOSUserBundle/Controller 内) と LoginManager.php (セキュリティ内) を調べてください。Symfony Security を使用してユーザーを認証する方法の例があります。
コントローラー/ResettingController.php
/**
* Authenticate a user with Symfony Security
*
* @param \FOS\UserBundle\Model\UserInterface $user
* @param \Symfony\Component\HttpFoundation\Response $response
*/
protected function authenticateUser(UserInterface $user, Response $response)
{
try {
$this->container->get('fos_user.security.login_manager')->loginUser(
$this->container->getParameter('fos_user.firewall_name'),
$user,
$response);
} catch (AccountStatusException $ex) {
// We simply do not authenticate users which do not pass the user
// checker (not enabled, expired, etc.).
}
}
および Security/LoginManager.php で
final public function loginUser($firewallName, UserInterface $user, Response $response = null)
{
$this->userChecker->checkPostAuth($user);
$token = $this->createToken($firewallName, $user);
if ($this->container->isScopeActive('request')) {
$this->sessionStrategy->onAuthentication($this->container->get('request'), $token);
if (null !== $response) {
$rememberMeServices = null;
if ($this->container->has('security.authentication.rememberme.services.persistent.'.$firewallName)) {
$rememberMeServices = $this->container->get('security.authentication.rememberme.services.persistent.'.$firewallName);
} elseif ($this->container->has('security.authentication.rememberme.services.simplehash.'.$firewallName)) {
$rememberMeServices = $this->container->get('security.authentication.rememberme.services.simplehash.'.$firewallName);
}
if ($rememberMeServices instanceof RememberMeServicesInterface) {
$rememberMeServices->loginSuccess($this->container->get('request'), $response, $token);
}
}
}
$this->securityContext->setToken($token);
}