1

I am having trouble getting a login page to work on the www subdomain. The security for the login is as follows:

firewalls: main: pattern: ^/ host: my.mydomain.dev form_login: check_path: '/login_check' login_path: '/login' default_target_path: '/' provider: fos_userbundle csrf_provider: form.csrf_provider logout: path: '/logout' target: '/login' anonymous: true switch_user: true access_control: # ASSETS NEEDED ON ALL PAGES # - { path: ^/assets/img, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/assets/css, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/assets/js, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/_wdt, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/_profiler, role: IS_AUTHENTICATED_ANONYMOUSLY } # END ASSETS NEEDED ON ALL PAGES # - { path: ^/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/login_check, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/, roles: ROLE_USER, host: my.domain.dev } - { path: ^/, host: linkmetrix.dev, roles: IS_AUTHENTICATED_ANONYMOUSLY } 

I have a login page at www.mydomain.com/login and a login page at my.mydomain.com/login.

When I login to the page at my.mydomain.com/login it works perfectly. Trying to figure out how to get a login page at www.mydomain.com/login to coincide with that, where the end result will take me to my.mydomain.com

Thanks for any help!

I have tried to create a second firewall for the front end, but nothing I have done seems to work. Any advice, techniques or tips greatly appreciated.

3 Answers 3

1

I had a similar issue and found out that I needed to adjust the domain that is set in the session cookie when the user is logged in. The reason being that the sub domain is set to where the user logged in so eliminating the sub-domain portion from the session fixed the issue.

Go to the config.yml file and add this line:

framework: session: cookie_domain: "domain.com" 
Sign up to request clarification or add additional context in comments.

Comments

0

Symfony should not care which domain you are using for the firewall, try removing the host: my.mydomain.dev directive.

Comments

0

Every domain/subdomain needs to have the firewall properly configured with the relative access_control.

Then you need to add to your access_control:

Wrong:

- { path: ^/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/login_check, roles: IS_AUTHENTICATED_ANONYMOUSLY }

Correct:

- { host: my.domain.dev, path: ^/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { host: my.domain.dev, path: ^/login_check, roles: IS_AUTHENTICATED_ANONYMOUSLY }

So for any domain you need to add the host: param on access_control.

I don't know your use case and why you need that but you can specify the target path in any firewall you want with

form_login: always_use_default_target_path: true default_target_path: your_target_path

EDIT: But user, after the redirect, will probably have some authentication problem because multiple firewalls don't share security context. An alternative to resolve the problem is to add the same context directive as described in the DOCS

1 Comment

That makes sense, so a firewall for my.domain.dev and www.domain.dev and the access_control to match. With this, how would I get it to automatically redirect from www.domain.dev/login to my.domain.dev upon successful login?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.