简体   繁体   English

Symfony2 + Rest登录+ FOSUserBundle

[英]Symfony2 + Rest login + FOSUserBundle

I don't really understand how to connect my users using a REST api. 我不太了解如何使用REST API连接用户。

For example I can add a new firewall 例如,我可以添加一个新的防火墙

firewalls:
    api:         
        pattern: ^/api
        anonymous: ~
        form_login: false            
        provider: fos_user_bundle
        http_basic:
            realm: "REST Service Realm"

But I don't understand how to connect my user. 但是我不知道如何连接用户。

And once the connection was successful, I have to send datas on each request to prove that my user is connected because there is no cookies. 一旦连接成功,我就必须发送每个请求的数据,以证明我的用户已连接,因为没有cookie。

Thanks for your help 谢谢你的帮助

When you use http based authentication (as you do with http_basic param) the authentication/authorization is managed by http headers. 当您使用基于http的身份验证时(与使用http_basic参数一样),身份验证/授权由http标头管理。

The server send to the client an header like this: 服务器将这样的标头发送给客户端:

WWW-Authenticate: Basic realm="REST Service Realm" 

That browsers usually alert user with a window thats ask for user/password. 该浏览器通常会通过询问用户/密码的窗口来警告用户。

The client should send to the server an header with: 客户端应将带有以下内容的标头发送到服务器:

Authorization: Basic {string} 

with string that is the encoded Base64("username:password") 带有编码为Base64(“ username:password”)的字符串

Every request must have this header. 每个请求都必须具有此标头。

All is described in RFC 2617 所有内容均在RFC 2617中进行了描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM