[英]handling the The CSRF token in symfony's forms when in public REST context
我是我的第一個 symfony (3) 應用程序的開發者。 它是一種可公開訪問的REST 服務。 我正在使用 FOSRestBundle 執行此操作。 我遲早要添加一些管理表單,我可能想直接創建它們(不通過使用我自己的 Web 服務的額外工作)
我想知道在這種情況下如何處理 CSRF 令牌。 我看到不同的解決方案:
這個(或其他)解決方案中的哪一個對您來說是最好的,您將如何對其進行編碼?
我找到了一種方法,也許不是最好的方法,但它有效:
$_format = $request->attributes->get('_format');
if ('html' == $_format) {
$form = $this->createForm(ItopInstanceUserType::class, $itopInstanceUser);
} else {
$form = $this->createForm(ItopInstanceUserType::class, $itopInstanceUser, ['csrf_protection' => false]);
}
對我來說,忘記自己管理的 CSRF 令牌,檢查 Oauth 身份驗證等主題。
看看這里: https : //github.com/FriendsOfSymfony/FOSOAuthServerBundle/blob/master/Resources/doc/index.md
FOSOAuthServerBundle 與 FOSRestBundle 完美配合。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.