Search code examples
phpsymfonyroutesrequestget

Get url method not recognized with Symfony


I have a little problem, the get method passing in the url is not recognized on other routes than the home '/'

example: /test?foo=bar

When I dump $_GET on my home route 'website.domain?foo=bar' I get foo=bar but when I dump $_GET on another route like 'website.domain/test?foo=bar' I get nothing in my $_GET dump, an empty array is returned.

[EDIT] Locally everything works normally, it's on server I have this problem.

security.yaml

security:
    enable_authenticator_manager: true
    # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords


    # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
    providers:
        # used to reload user from session & other features (e.g. switch_user)
        users_in_memory: { memory: null }
        my_provider:
            entity: {class: App\Entity\User, property: uuid}
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            lazy: true
            provider: my_provider
            custom_authenticators:
               - App\Security\AzureAuthenticator
            logout: true

      # activate different ways to authenticate
      # https://symfony.com/doc/current/security.html#firewalls-authentication

      # https://symfony.com/doc/current/security/impersonating_user.html
      # switch_user: true

  # Easy way to control access for large sections of your site
  # Note: Only the *first* access control that matches will be used
    access_control:
     - { path: ^/connect/azure, role: PUBLIC_ACCESS }
     - { path: ^/, roles: ROLE_USER}

.htaccess

# https://docs.microsoft.com/fr-fr/azure/app-service/configure-language-php?pivots=platform-linux#change-site-root
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^(.*)
    RewriteRule ^(.*)$ /public/$1 [NC,L,QSA]
</IfModule>

php_value upload_max_filesize 100M
php_value memory_limit 300M

AzureController.php

<?php

namespace App\Controller;

use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class AzureController extends AbstractController
{
    /**
     * Cette fonction effectue la connexion avec Azure
     * Ex: Si vous allez sur cette route, un formulaire microsoft vous demandera de vous connecter
     */
    #[Route('/connect/azure', name: 'connect_azure')]
    public function connectAction(ClientRegistry $clientRegistry, Request $request)
    {
        $foo = $request->query->get('foo');
        dd($foo);
        return $clientRegistry
        ->getClient('azure')
        ->redirect([
            'openid', 'profile', 'email'
        ], []);
            
    }

    /**
     * Cette fonction permet de savoir si l'authentification à réussi
     * Ex: Après vous être connecté ci-dessus, vous serez rediriger sur cette route qui vous redirigera à son tour vers la route home
     */
    #[Route('/connect/azure/check', name: 'connect_azure_check', schemes:['http'])]
    public function connectCheckAction(Request $request, ClientRegistry $clientRegistry)
    {
        try {
            return $this->redirectToRoute('home');
        } catch (IdentityProviderException $e) {
            return new JsonResponse(array('status' => false, 'message' => "User not found!", 'error' => $e->getMessage()));
        }

    }
}

nginx.conf

server {
    #proxy_cache cache;
    #proxy_cache_valid 200 1s;
    listen 8080;
    listen [::]:8080;
    root /home/site/wwwroot/public;
    index  index.php index.html index.htm;
    server_name  example.com www.example.com; 
    port_in_redirect off;
    client_max_body_size 1000M;

    location / {            
        try_files $uri $uri/ /index.php?$args;
    }

    error_page 404 /index.php;
   
    # Disable .git directory
    location ~ /\.git {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Add locations of phpmyadmin here.
    location ~ [^/]\.php(/|$) {
        try_files $uri =404;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param HTTP_PROXY "";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_intercept_errors on;
        fastcgi_connect_timeout         300; 
        fastcgi_send_timeout           3600; 
        fastcgi_read_timeout           3600;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}

I can't find any solution on internet, maybe my search is wrong. Do you have any ideas ?


Solution

  • I have found my problem, is the nginx.conf file.

    My new Nginx.conf

    server {
        #proxy_cache cache;
        #proxy_cache_valid 200 1s;
        listen 8080;
        listen [::]:8080;
        root /home/site/wwwroot/public;
        index  index.php index.html index.htm;
        server_name  example.com www.example.com; 
        port_in_redirect off;
        client_max_body_size 1000M;
    
        location / {            
            try_files $uri $uri/ /index.php$is_args$args;
        }
    
        error_page 404 /index.php;
       
        # Disable .git directory
        location ~ /\.git {
            deny all;
            access_log off;
            log_not_found off;
        }
    
        # Add locations of phpmyadmin here.
        location ~ ^/index\.php(/|$) {
            try_files $uri =404;
            fastcgi_index index.php;
            fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
            fastcgi_pass 127.0.0.1:9000;
            include fastcgi_params;
            fastcgi_param HTTP_PROXY "";
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param QUERY_STRING $query_string;
            fastcgi_intercept_errors on;
            fastcgi_connect_timeout         300; 
            fastcgi_send_timeout           3600; 
            fastcgi_read_timeout           3600;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 4 256k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
        }
    
        error_log /var/log/nginx/project_error.log;
        access_log /var/log/nginx/project_access.log;
    }