简体   繁体   中英

Symfony 5 - How implement basic authentication on REST call

I have created a URL that take a request in method POST. He take a JSON and he return me a XML converted file.

I would like, before the request, a basic authorization ( just a password, i need not registered user )on this URL to allow the user make the request. But i don't understand how the authorization working on symfony.

I think that all i need is in this page of documentation but i get some errors and i not understand how it work (what is realme? What does it mean with Secured Area?)

This is my controller, how can i implement a basic authentication on this REST call?

class IndexController extends AbstractController
{

    /**
     * @Route("/converter-hl7", name="converter", methods={"POST"})
     */

    public function index(Request $request) {

        $json = $request->getContent();

        $converter = new HL7ConverterService($json, new ErrorService());
        $xml = $converter->outputXML();


        $response = new Response($xml);
        $response->headers->set('Content-Type', 'xml');

        return $response;
    }
    

}

i use JWT for my API's to Control and Secure Api access
you should check this Bundle But to use this you need to create user. if you don't want to create a user you could demand a password from the sender and integrate it in the request then control access based on that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM