api platform :LexikJWTAuthenticationBundle Failed to load private key - php

im using api paltform to create an authentification api following there tutorial.
https://api-platform.com/docs/core/jwt
i got this probleme:
Failed to load private key
"C:\wamp64\www\auth-api\app/../var/jwt/private.pem": 0906A068:PEM
routines:PEM_do_header:bad password read
security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
login:
pattern: ^/login
stateless: true
anonymous: true
provider: fos_userbundle
form_login:
check_path: /login_check
username_parameter: _username
password_parameter: _password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
main:
pattern: ^/
provider: fos_userbundle
stateless: true
anonymous: true
lexik_jwt: ~
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: IS_AUTHENTICATED_FULLY }
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the
app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
# Nelmio CORS
nelmio_cors:
defaults:
allow_origin: ["%cors_allow_origin%"]
allow_methods: ["POST", "PUT", "GET", "DELETE", "OPTIONS"]
allow_headers: ["content-type", "authorization"]
expose_headers: ["link"]
max_age: 3600
paths:
'^/': ~
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\Entity\User
from_email:
address: noreplay#noreplay.com
sender_name: noreplay
lexik_jwt_authentication:
private_key_path: '%jwt_private_key_path%'
public_key_path: '%jwt_public_key_path%'
pass_phrase: '%jwt_key_pass_phrase%'
token_ttl: '%jwt_token_ttl%'
routing.yml
api:
resource: '.'
type: 'api_platform'
app:
resource: '#AppBundle/Action/'
type: 'annotation'
fos_user:
resource: "#FOSUserBundle/Resources/config/routing/all.xml"
login_check:
path: /login_check

When you install LexikJWTAuthenticatioBundle you need to launch this command from your console
$ openssl genrsa -out var/jwt/private.pem -aes256 4096
$ openssl rsa -pubout -in var/jwt/private.pem -out var/jwt/public.pem
You need to insert a password and add It to your parameters.yml assgined to variable: jwt_key_pass_phrase
Like this:
jwt_key_pass_phrase: ''

You should look directly in the docs of LexikJWTAuthenticationBundle since this is not really linked to api-platform.
It may mean that the private key is wrong.

Related

Setup Facebook login with HWIOAuthBundle, symfony 3

I'm using HWIOAuthBundle to setup a facebook login but while I'm running the path : http://localhost:8000/connect orhttp://localhost:8000/connect/check-facebook
he failed to load the page with no error msg just a web browser error
:ERR_TOO_MANY_REDIRECTS
routing.yml
api:
resource: '.'
type: 'api_platform'
app:
resource: '#AppBundle/Action/'
type: 'annotation'
api_login_check:
path: /api/login_check
hwi_oauth_redirect:
resource: "#HWIOAuthBundle/Resources/config/routing/redirect.xml"
prefix: /connect
hwi_oauth_connect:
resource: "#HWIOAuthBundle/Resources/config/routing/connect.xml"
prefix: /connect
hwi_oauth_login:
resource: "#HWIOAuthBundle/Resources/config/routing/login.xml"
prefix: /connect
facebook_login:
path: /connect/check-facebook
fos_user_security:
resource: "#FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "#FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "#FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /account/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
fos_user:
resource: "#FOSUserBundle/Resources/config/routing/all.xml"
security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_READER: ROLE_USER
ROLE_ADMIN: ROLE_READER
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
login:
pattern: ^/login
stateless: true
anonymous: true
provider: fos_userbundle
form_login:
check_path: /login_check
username_parameter: _username
password_parameter: _password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_id: form.csrf_provider
login_path: /login
check_path: /login_check
# if you are using Symfony < 2.8, use the following config instead:
# csrf_provider: form.csrf_provider
oauth:
resource_owners:
facebook: "/connect/check-facebook"
login_path: /connect
use_forward: false
failure_path: /connect
default_target_path: /
oauth_user_provider:
service: hwi_oauth.user.provider.fosub_bridge
lexik_jwt: ~
logout:
path: /logout
target: /login
anonymous: true
stateless: true
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
access_control:
- { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/books, roles: [ ROLE_READER ] }
- { path: ^/, roles: [ ROLE_READER ] }
- { path: ^/logout, role: IS_AUTHENTICATED_ANONYMOUSLY }
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
# Nelmio CORS
nelmio_cors:
defaults:
allow_origin: ["%cors_allow_origin%"]
allow_methods: ["POST", "PUT", "GET", "DELETE", "OPTIONS"]
allow_headers: ["content-type", "authorization"]
expose_headers: ["link"]
max_age: 3600
paths:
'^/': ~
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: AppBundle\Entity\User
use_username_form_type: false
lexik_jwt_authentication:
private_key_path: '%jwt_private_key_path%'
public_key_path: '%jwt_public_key_path%'
pass_phrase: '%jwt_key_pass_phrase%'
token_ttl: '%jwt_token_ttl%'
hwi_oauth:
connect:
confirmation: true
registration_form: fos_user.registration.form.factory
firewall_names: [main]
fosub:
username_iterations: 30
properties:
facebook: facebookID
resource_owners:
# Facebook Access
facebook:
type: facebook
client_id: '%oauth.facebook.id%'
client_secret: '%oauth.facebook.secret%'
scope: "email"
options:
display: popup
csrf: true
I'm not sure is this the cause of the issue, but at a first look I think you forgot to configure the OAuth Firewall to make the /connect and /connect/check-facebook routes accessible by anonymous users.
So you should add in your security.yml:
access_control:
- { path: ^/connect, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/connect/check-facebook, role: IS_AUTHENTICATED_ANONYMOUSLY }
To prevent unexpected conflict, it's also recommended to "import" all OAuth routes at the very first place in your app/config/routing.yml:
To prevent strange issues, this route should be imported before your
custom ones.

PHP Symfony3 - HWIOAuthBundle: Facebook Login redirecting problems

At the start, I can say that I had implemented the Facebook Login button and after I'm clicking on it, it's asking me for login details > app allow > and after I'm trying to put my credentials, is not redirecting me on dashboard, and is not logging me in.
How can I make the login to work, and after to redirect me on www.example.com/dashboard
1)config.yml looks like this:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: de
framework:
#esi: ~
translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
form_themes:
- 'common/form.html.twig'
- 'VichUploaderBundle:Form:fields.html.twig'
globals:
host: "%host%"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
# charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
dql:
string_functions:
MONTH: DoctrineExtensions\Query\Mysql\Month
YEAR: DoctrineExtensions\Query\Mysql\Year
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
auth_mode: "%mailer_authmode%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
scssphp:
formatter: 'Leafo\ScssPhp\Formatter\Compressed'
# FOSUserBundle configuration
fos_user:
db_driver: orm
firewall_name: main
user_class: MyDinxx\UserBundle\Entity\User
from_email:
address: noreply#mydinxx.de
sender_name: MyDinxx
registration:
form:
type: MyDinxx\UserBundle\Form\RegistrationType # override default registration form
confirmation:
enabled: true # enable E-Mail confirmation
# FOSMessageBundle configuration
fos_message:
db_driver: orm
thread_class: MyDinxx\UserBundle\Entity\Thread
message_class: MyDinxx\UserBundle\Entity\Message
# VichUploaderBundle configuration (avatars)
vich_uploader:
db_driver: orm
mappings:
avatar:
uri_prefix: /upload/avatar
upload_destination: '%kernel.root_dir%/../web/upload/avatar'
namer:
service: vich_uploader.namer_property
options: { property: 'id'}
# HWIOAuthBundle
hwi_oauth:
connect:
confirmation: true
registration_form: fos_user.registration.form.factory
firewall_names: [secured_area]
fosub:
username_iterations: 30
properties:
facebook: facebookID
resource_owners:
facebook:
type: facebook
client_id: #myClientID(after I've created the app on faceobok developers)
client_secret: #myClientSecret(after I created the app on faceobok developers)
scope: "email"
2)routing.yml looks like this:
AppBundle:
resource: "#AppBundle/Controller/"
type: annotation
FrontendBundle:
resource: "#FrontendBundle/Controller/"
type: annotation
FOSUserBundle:
resource: "#FOSUserBundle/Resources/config/routing/all.xml"
FOSMessageBundle:
resource: "#FOSMessageBundle/Resources/config/routing.xml"
prefix: /messenger
MyDinxxUserBundle:
resource: "#UserBundle/Controller/"
type: annotation
# HWIOAuthBundle
hwi_oauth_redirect:
resource: "#HWIOAuthBundle/Resources/config/routing/redirect.xml"
prefix: /connect
hwi_oauth_connect:
resource: "#HWIOAuthBundle/Resources/config/routing/connect.xml"
prefix: /connect
hwi_oauth_login:
resource: "#HWIOAuthBundle/Resources/config/routing/login.xml"
prefix: /login
3)security.yml looks like this:
# To get started with security, check out the documentation:
# http://symfony.com/doc/current/book/security.html
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
logout: true
anonymous: true
remember_me:
secret: '%secret%'
lifetime: 604800 # 1 week in seconds
path: /
# by default, the feature is enabled by checking a
# checkbox in the login form (see below), uncomment the
# following line to always enable it.
#always_remember_me: true
secured_area:
anonymous: ~
oauth:
resource_owners:
facebook: "/login/check-facebook"
google: "/login/check-google"
my_custom_provider: "/login/check-custom"
my_github: "/login/check-github"
login_path: /login
use_forward: false
failure_path: /login
oauth_user_provider:
service: hwi_oauth.user.provider.fosub_bridge
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/shipment, roles: ROLE_USER }
I tried and I think I've made all possible configs.. and remain without ideas.
In my database, I have a column named facebook_id (varchar, nullable), and, in my User Entity I've put it as:
/**
* FacebookID of user
*
* #ORM\Column(type="string", name="facebook_id", nullable=true)
*/
protected $facebookID;
My setup looks like this : in case it helps..
main:
pattern: ^/
form_login:
login_path: /prelogin
#success_handler: authentication.handler.login_success_handler
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
always_use_default_target_path: false
default_target_path: /start
#use_referer: true
# if you are using Symfony < 2.8, use the following config instead:
# csrf_provider: form.csrf_provider
oauth:
failure_path: start
login_path: /prelogin
check_path: /connect_check
default_target_path: /start
provider: fos_userbundle
resource_owners:
facebook: "/login/check-facebook"
google: "/login/check-google"
twitter: "/login/check-twitter"
linkedin: "/login/check-linkedin"
oauth_user_provider:
service: app.provider.oauth
logout: true
anonymous: true
Try playing around with the default_target_path and check_path settings ..
config.yml part:
hwi_oauth:
# name of the firewall in which this bundle is active, this setting MUST be set
firewall_names: [main]
connect:
account_connector: app.provider.oauth
resource_owners:
facebook:
type: facebook
client_id: %facebook_client_id%
client_secret: %facebook_client_secret%
scope: "email, public_profile"
infos_url: "https://graph.facebook.com/me?fields=id,name,email,picture.type(large)"
paths:
email: email
options:
display: popup #dialog is optimized for popup window
auth_type: rerequest # Re-asking for Declined Permissions
routing.yml part:
facebook_login:
path: /login/check-facebook
hwi_oauth_redirect:
resource: "#HWIOAuthBundle/Resources/config/routing/redirect.xml"
prefix: /connect
hwi_oauth_connect:
resource: "#HWIOAuthBundle/Resources/config/routing/connect.xml"
prefix: /connect
hwi_oauth_login:
resource: "#HWIOAuthBundle/Resources/config/routing/login.xml"
prefix: /login

Symfony\Component\Config\Definition\Exception\InvalidTypeException on Symfony2.8

I'm trying to set a login with FosUserBundle on Synfony 2.8 but I gte this error when I try to start the server
[Symfony\Component\Config\Definition\Exception\InvalidTypeException]
Invalid type for path "security.firewalls.pattern". Expected array,
but got string
This is the security.yml file
# To get started with security, check out the documentation:
# http://symfony.com/doc/current/book/security.html
security:
providers:
in_memory:
memory: ~
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
logout: true
anonymous: true
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
# activate different ways to authenticate
# http_basic: ~
# http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate
# form_login: ~
# http://symfony.com/doc/current/cookbook/security/form_login_setup.html
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
encoders:
UserBundle\Entity\User:
algorithm: bcrypt
cost: 12
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
and this is the config.yml file
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#UserBundle/Resources/config/services.yml" }
parameters:
locale: en
framework:
translator: { fallbacks: [en] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: es
trusted_hosts: ~
trusted_proxies: ~
session:
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: AppBundle\Entity\User
I think I've followed the official doc but It doesn't work
It looks like you have to refactor yor firewalls:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
logout: true
anonymous: true

Unrecognized option “csrf_token_generator” under “security.firewalls.main.form_login”

I'm trying to install the FOSUserBundle following the tutorial: https://symfony.com/doc/master/bundles/FOSUserBundle/index.html
but appears the error :
InvalidConfigurationException: Unrecognized options "csrf_token_generator" under "security.firewalls.main.form_login"
My config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
framework:
csrf_protection:
enabled: true
#esi: ~
#translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Utilisateurs\UtilisateursBundle\Entity\Utilisateurs
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
My security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
# if you are using Symfony < 2.8, use the following config instead:
csrf_provider: form.csrf_provider
logout: true
anonymous: true
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/demo/secured/login$
security: false
secured_area:
pattern: ^/demo/secured/
form_login:
check_path: _security_check
login_path: _demo_login
logout:
path: _demo_logout
target: _demo
#anonymous: ~
#http_basic:
# realm: "Secured Demo Area"
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, role: ROLE_ADMIN }
enter code here
Can someone help me ?
The problem is in your security.yml file. You have listed two CSRF token managers.
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
# if you are using Symfony < 2.8, use the following config instead:
# csrf_provider: form.csrf_provider
Depending on what version of Symfony you are using you use either csrf_token_generator or csrf_provider if your version of Symfony is <2.8, not both.
You need to remove or comment one of the lines out.
Editing this post because I cannot comment on your new post.
My version symfony is 2.4 : "symfony/symfony": "2.4.*"
But i have these new error:
ServiceNotFoundException: You have requested a non-existent service "fos_user.doctrine_registry".
This could be due to your version of Symfony being <2.6.* and conflicting with the FOSUserBundle version you are using.
For a temporary work around edit your config.yml
services:
fos_user.doctrine_registry:
alias: doctrine
# or use this, unsure on which one for your version of Symfony
# alias: doctrine_mongodb
Other fixes could be using a particular pull (older version - not recommended) in your composer.json. This has been tested for Symfony 2.6.* and bypassing the same issue you posted.
"friendsofsymfony/user-bundle": "dev-master##6ccff96434c0ac7fee077d1dce90966341dfd278"
You can read more about this particular problem:
https://github.com/FriendsOfSymfony/FOSUserBundle/issues/2048
A Symfony branch exists as a temporary fix as well:
https://github.com/symfony/symfony/pull/17554

FOSUserBundle Authentication not working on production server

I am new to Symfony, and probably thats why i don't seem to be able to target where the certain bugs generate from.
A new problem popped up when i put my site on the production server, the FOSUserBundle Authentication doesn't seem to work
Note: This worked absolutely fine on localhost, but as soon as i put it on the distant server, it does not validate any user.
The web/config.php file recommends that i :
1) Install and enable the php_posix extension (used to colorize the CLI output).
2) Install and enable the intl extension (used for validators)
3) Install and enable a PHP accelerator like APC (highly recommended).
4) Set short_open_tag to off in php.ini*.
Could this cause problems in Authentication ?
my config.yml file
imports:
- { resource: parameters.yml }
- { resource: security.yml }
framework:
#esi: ~
translator: { fallback: "%locale%" }
translator: ~
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ LesCouvertsBundle , LesRestaurantBundle , LesVirtualMarketBundle , LesShopBundle ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
encryption: ssl
auth_mode: login
spool: { type: memory }
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Les\UserBundle\Entity\User
registration:
confirmation:
from_email:
address: registration#lescouverts.com
sender_name: Lescouverts Registration
enabled: false
from_email:
address: noreply#lescouverts.com
sender_name: LesCouverts
services:
resto_module:
class: Les\RestoModule\Module
arguments: [module]
lists_module:
class: Les\RestoParam\Param
arguments: [parameters]
my security.yml file
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_CLIENT: ROLE_USER
ROLE_RESTO: ROLE_CLIENT
ROLE_SHOP: ROLE_CLIENT
ROLE_ADMIN: [ ROLE_USER, ROLE_CLIENT, ROLE_RESTO , ROLE_SHOP ]
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
login_path: fos_user_security_login
csrf_provider: form.csrf_provider
# check_path: /login_check
check_path: fos_user_security_check
default_target_path: /
csrf_provider: form.csrf_provider
logout:
path: fos_user_security_logout
anonymous: true
access_control:
- { path: ^/booking, role: ROLE_CLIENT }
- { path: ^/party_calendar, role: ROLE_CLIENT }
- { path: ^/restaurant_admin, role: ROLE_RESTO }
- { path: ^/shop_admin, role: ROLE_SHOP }
- { path: ^/virtual_market, role: [ ROLE_RESTO, ROLE_SHOP ] }
- { path: ^/root, role: ROLE_ADMIN }
- { path: ^/secure_area/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/secure_area/connect, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/secure_area, role: ROLE_USER }
I am not sure how to debug this problem!
Plus in development mode i am getting the error
RuntimeException: Failed to write cache file
"/var/www/vhosts/httpdocs/app/cache/dev/classes.php".
So i cant even see if the profiler is indicating any errors!
One common issue is that the app/cache and app/logs directories must be writable both by the web server and the command line user.
http://symfony.com/doc/current/book/installation.html#configuration-and-setup

Categories