reactjs - Sharing session between React front-end server and PHP/Symfony back-end server -
i have application consists of front-end server running react , back-end server running php/symfony. part of front-end developed using twig templates (mostly backoffice forms updating content) , handled same back-end server, , part of developed using react , resides in separated front-end server (for public user access, more functionality).
the system has 3 user roles: superadmin (authenticated through form against in-memory user configured in symfony), backoffice employee (authenticated through same form against user entity in database) , "public user" sort of speak, uses public side of application, authenticated through third party service which, in end, requires start session inside 1 of our apis code similar this:
$token = new usernamepasswordtoken($publicuserentity, null, 'main', $publicuserentity->getroles()); $this->get('security.token_storage')->settoken($token); $this->get('session')->set('_security_main', serialize($token)); users authenticated in 3 ways, session open if in backend server , not if make request frontend server.
for example, after login public user, if make request to:
http://backendserverhost/api/someentity/me that api loads current session's user id user's data, , proper response according authenticated user.
but if make same request frontend server (to same api, , same endpoint) in order same information , show it, returns error if anonymous user.
what changes should able "use" opened session in backend server make frontend server requests?
you can generate token user , pass argument @ each request.
using fosoauthrestbundle can define accesstoken in user model class , use authenticate @ each request.
they have pretty tutorial here: https://github.com/friendsofsymfony/fosoauthserverbundle/blob/master/resources/doc/index.md
Comments
Post a Comment