[英]facebook and github login HWIOAuthBundle and FOSUserBundle in Symfony2.1
我已經按照Tututial http://m2mdas.github.io/blog/2013/11/21/integrate-hwioauthbundle-with-fosuserbundle/的要求進行了Github登錄工作,這似乎和我單擊登錄時一樣有效登陸github登錄頁面,我可以在github儀表板上的github應用程序上看到1個用戶注冊。 但是我沒有在Symfony中得到認證。 在我底部的symfony工具欄上,它仍然說我是一個匿名用戶,並且還沒有在表fos_user中添加新行。
對於facebook登錄,當我單擊facebook的生成器登錄鏈接時,它給我錯誤“應用程序配置不允許給定URL 。:應用程序的設置不允許一個或多個給定URL。它必須匹配網站URL或Canvas URL,或者域必須是該應用程序域之一的子域。”
我的另一個疑問是,在教程中,它說要放在routing.yml中,
hwi_github_login:
pattern: /secure_area/login/check-github
由於未指定控制器或資源,我應該在此處輸入什么作為控制器操作路徑或資源?
fos_user:db_driver:orm#其他有效值是'mongodb','couchdb'和'propel'Firewall_name:主user_class:Les \\ UserBundle \\ Entity \\ User注冊:確認:啟用:true
hwi_oauth:#此捆綁包在其中處於活動狀態的防火牆的名稱,必須設置以下設置firewall_name:secure_area connect:確認:true #account_connector:hwi_oauth.user.provider.fosub_bridge #registration_form_handler:hwi_oauth.registration.form.handler.fosub_bridge# registration_form:fos_user.registration.form
resource_owners:
github:
type: github
client_id: b625ec98906cc26ad4f1
client_secret: a3505d93ab1fc6c5a7fa2805c0723bbfddf556a7
scope: "user:email"
facebook:
type: facebook
client_id: 331922526960400
client_secret: 9dc32a145a1c6b0b7f5e57a34d174011
fosub:
# try 30 times to check if a username is available (foo, foo1, foo2 etc)
username_iterations: 30
# mapping between resource owners (see below) and properties
properties:
github: githubID
facebook: fbID
安全性:編碼器:FOS \\ UserBundle \\ Model \\ UserInterface:sha512
role_hierarchy:
ROLE_CLIENT: ROLE_USER
ROLE_RESTO: ROLE_CLIENT
ROLE_ADMIN: [ ROLE_USER, ROLE_CLIENT, ROLE_RESTO ]
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
secure_area:
pattern: ^/secure_area
oauth:
failure_path: /secure_area/connect
login_path: /secure_area/connect
check_path: /secure_area/connect
provider: fos_userbundle
resource_owners:
github: "/secure_area/login/check-github"
facebook: "/secure_area/login/check-facebook"
oauth_user_provider:
service: hwi_oauth.user.provider.fosub_bridge
anonymous: true
logout:
path: /secure_area/logout
target: / #where to go after logout
access_control:
- { path: ^/booking, role: ROLE_CLIENT }
- { path: ^/party_calendar, role: ROLE_CLIENT }
- { path: ^/restaurant_admin, role: ROLE_RESTO }
- { path: ^/secure_area/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/secure_area/connect, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/secure_area, role: ROLE_USER }
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
prefix: /login
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
hwi_oauth_redirect:
resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
prefix: /secure_area/connect
hwi_oauth_login:
resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
prefix: /secure_area/connect
hwi_oauth_connect:
resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
prefix: /secure_area/connect
hwi_github_login:
pattern: /secure_area/login/check-github
defaults: { _controller: LesCouvertsBundle:Couverts:index }
hwi_facebook_login:
pattern: /secure_area/login/check-facebook
defaults: { _controller: LesCouvertsBundle:Couverts:index }
hwi_google_login:
pattern: /secure_area/login/check-google
defaults: { _controller: LesCouvertsBundle:Couverts:index }
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="githubId", type="string", nullable=true)
*/
private $githubID;
/**
* @var string
*
* @ORM\Column(name="githubId", type="string", nullable=true)
*/
private $fbID;
public function __construct()
{
parent::__construct();
// your own logic
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @param string $githubID
*/
public function setGithubID($githubID)
{
$this->githubID = $githubID;
}
/**
* @return string
*/
public function getGithubID()
{
return $this->githubID;
}
/**
* @param string $fbID
*/
public function setFbID($fbID)
{
$this->fbID = $fbID;
}
/**
* @return string
*/
public function getFbID()
{
return $this->fbID;
}
}
錯誤:
“應用程序配置不允許使用URL 。:應用程序的設置不允許使用一個或多個給定URL。它必須與網站URL或Canvas URL匹配,或者該域必須是該應用程序域之一的子域“。
當您登錄Facebook應用程序的域與您在Facebook應用程序的“設置”選項卡上設置的應用程序域不匹配時發生。
例如,如果您從“ http:/www.yoursite.com”登錄,則需要將“ yoursite.com”設置為應用程序上的應用程序域。
關於您無法將用戶插入數據庫的其他問題,請檢查以下指南,該指南不僅進行注冊,而且在注冊后自動登錄用戶:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.