Visualizzazione dei risultati da 1 a 10 su 10
  1. #1

    Problemi con invio/ricezione HTTP_AUTHORIZATION

    ciao.

    sto cercando di inviare una autenticazione Bearer ad uno script PHP:
    Codice PHP:
    header("Access-Control-Allow-Origin: * ");
    header("Content-Type: application/json; charset=UTF-8");
    header("Access-Control-Allow-Methods: GET");
    header("Access-Control-Max-Age: 3600");
    header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

    var_dump($_SERVER['HTTP_AUTHORIZATION']); 
    i dati i sto inviando con postman, ed ho aggiunto i dati corretti.
    questo l'esempio di codice che mi da:
    Codice PHP:
    $curl curl_init();

    curl_setopt_array($curl, array(
      
    CURLOPT_URL => "..............",
      
    CURLOPT_RETURNTRANSFER => true,
      
    CURLOPT_ENCODING => "",
      
    CURLOPT_MAXREDIRS => 10,
      
    CURLOPT_TIMEOUT => 0,
      
    CURLOPT_FOLLOWLOCATION => true,
      
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      
    CURLOPT_CUSTOMREQUEST => "GET",
      
    CURLOPT_HTTPHEADER => array(
        
    "Content-Type: application/json",
        
    "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJUSEVfSVNTVUVSIiwiYXVkIjoiVEhFX0FVRElFTkNFIiwiaWF0IjoxNTgxOTM2MzQ2LCJuYmYiOjE1ODE5MzYzNTYsImV4cCI6MTU4MTkzNjQwNiwiZGF0YSI6eyJ1c2VybmFtZSI6Im1hdHRlIn19.-Zk-bn3AetfttQPe_Dsks9IGm6oxg880h7PYqagz6NU"
      
    ),
    ));

    $response curl_exec($curl);

    curl_close($curl);
    echo 
    $response
    il problema è che ricevo sempre NULL come risposta.
    come se non stessi inviando il token.
    suggerimenti??

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2016
    Messaggi
    783
    Prova a fare il dump di $_SERVER['Authorization'] e vedi se il token è li.

  3. #3
    ho modificato così:
    Codice PHP:
    header("Access-Control-Allow-Origin: * ");
    header("Content-Type: application/json; charset=UTF-8");
    header("Access-Control-Allow-Methods: GET");
    header("Access-Control-Max-Age: 3600");
    header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

    var_dump($_SERVER['Authorization']); 
    ma ottengo cmq un NULL.
    anche facendo il dump di tutto il $_SERVER non vedo il token.
    ma vedo CONTENT_TYPE "application/json".

  4. #4
    ho provato a mettere questo codice su un mio server, che non è su hosting condiviso, e vedo il token:
    Codice PHP:
    header("Access-Control-Allow-Origin: *");
    header("Content-Type: application/json; charset=UTF-8");
    header("Access-Control-Allow-Methods: GET");
    header("Access-Control-Max-Age: 3600");
    header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

    var_dump(getallheaders()); 
    invece sul server dove mi serve, che è su hosting condiviso, no.
    potrebbe essere quello il problema?

  5. #5
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,445
    In quel codice lì dov'è sta il token?

    Edit: nel senso, quello che ti vede il token dove lo trova tra gli header?

  6. #6
    ti metto tutta la risposta del server casalingo:
    Codice PHP:
    array(9) {
        [
            
    "Content-Type"
        
    ]=>
      
    string(16"application/json"
      
    [
            
    "Authorization"
        
    ]=>
      
    string(248"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJUSEVfSVNTVUVSIiwiYXVkIjoiVEhFX0FVRElFTkNFIiwiaWF0IjoxNTgxOTM2MzQ2LCJuYmYiOjE1ODE5MzYzNTYsImV4cCI6MTU4MTkzNjQwNiwiZGF0YSI6eyJ1c2VybmFtZSI6Im1hdHRlIn19.-Zk-bn3AetfttQPe_Dsks9IGm6oxg880h7PYqagz6NU"
      
    [
            
    "User-Agent"
        
    ]=>
      
    string(21"PostmanRuntime/7.22.0"
      
    [
            
    "Accept"
        
    ]=>
      
    string(3"*/*"
      
    [
            
    "Cache-Control"
        
    ]=>
      
    string(8"no-cache"
      
    [
            
    "Postman-Token"
        
    ]=>
      
    string(36"83b4264e-d05a-4f17-b266-0c9c9912cd6d"
      
    [
            
    "Host"
        
    ]=>
      
    string(16"dominio"
      
    [
            
    "Accept-Encoding"
        
    ]=>
      
    string(17"gzip, deflate, br"
      
    [
            
    "Connection"
        
    ]=>
      
    string(10"keep-alive"

    questa invece la risposta del server su hosting condiviso:
    Codice PHP:
    array(11) {
      [
        
    "Host"
      
    ]=>
      
    string(15"www.sito.it"
      
    [
        
    "X-Real-Ip"
      
    ]=>
      
    string(13"31.197.139.26"
      
    [
        
    "X-Forwarded-Port"
      
    ]=>
      
    string(3"443"
      
    [
        
    "X-Forwarded-Proto"
      
    ]=>
      
    string(5"https"
      
    [
        
    "Connection"
      
    ]=>
      
    string(5"close"
      
    [
        
    "Content-Type"
      
    ]=>
      
    string(16"application/json"
      
    [
        
    "User-Agent"
      
    ]=>
      
    string(21"PostmanRuntime/7.22.0"
      
    [
        
    "Accept"
      
    ]=>
      
    string(3"*/*"
      
    [
        
    "Cache-Control"
      
    ]=>
      
    string(8"no-cache"
      
    [
        
    "Postman-Token"
      
    ]=>
      
    string(36"cbca0684-f01e-4336-a761-562551b649ca"
      
    [
        
    "Accept-Encoding"
      
    ]=>
      
    string(17"gzip, deflate, br"


  7. #7
    Utente di HTML.it
    Registrato dal
    Sep 2016
    Messaggi
    783
    Sembra che sull'hosting condiviso tu sia dietro un reverse proxy che non passa le informazioni di auth.
    Però temo che l'unico modo di risolvere sia modificando la configurazione del reverse proxy.
    Prova in caso ad inviare un ticket all'hosting e vedere cosa ti dicono.

  8. #8
    Quote Originariamente inviata da M4V1 Visualizza il messaggio
    Sembra che sull'hosting condiviso tu sia dietro un reverse proxy che non passa le informazioni di auth.
    Però temo che l'unico modo di risolvere sia modificando la configurazione del reverse proxy.
    Prova in caso ad inviare un ticket all'hosting e vedere cosa ti dicono.
    si penso anche io una cosa del genere.
    invio un ticket, nel frattempo ho modificato il codice per inviare il token tramite query string.

  9. #9
    mi hanno fatto inserire questo dentro al file .htaccess ed ha funzionato:
    codice:
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

  10. #10
    Utente di HTML.it
    Registrato dal
    Sep 2016
    Messaggi
    783
    Probabilmente HTTP:Authorization (dove stava il token) non veniva passata dal proxy all'upstream, mentre HTTP_AUTHORIZATION si.
    Quindi ti hanno fatto copiare il valore di HTTP:Authorization in HTTP_AUTHORIZATION.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.