ElJackiste
ElJackiste

Reputation: 4591

Set token client side with Rest API in Symfony2

I made a Rest API with symfony2 on one server (S1).

I made an application with symfony2 on one server (S2).

S1 : Works well. It gives json response of user's informations, depends of url given.

S2 : Works well. Ask url with curl. Use wsse in the http header for retrieve important user's informations.

I want log in my users (from S2) using S1 database. But when i am in S2, after the json response with user's informations, i don't know what i need to do and how do it...

Application side : - Symfony2

API side : - Symfony2 - FOSUserBundle - FOSRestBundle - JMS

It's the first time i try to make an Rest API, so maybe i don't understand well how it works.

Thank's in advance.

EDIT : For more details.

Now my problem is that i need to do the same thing for a new page, but i don't want ask my user for a password and a username a second time because for him, he is log in.

Hope it's more clear.

EDIT 2 : My problem resume in one sentence.

In Symfony2, with wsse authentication, how can i get a user's token and send it to client side after authentication on the API.

:p

Upvotes: 2

Views: 1214

Answers (2)

Talus
Talus

Reputation: 754

Your S1 application returns a token when you authenticate from the S2 app, right ?

Then all you need to do is store this token somewhere in your S1 app (an entity, redis, ... Whatever), and when a foreign app (such as your S2 app) ask for a resource while providing this request with a token, you just gotta check out if the token exists and is valid.

If it is, then you can authenticate the user on the S1 with Symfony's security component.

Upvotes: 0

Debreczeni András
Debreczeni András

Reputation: 1678

You need to create a custom authentication. Fortunately for you, this Symfony cookbok entry will show you how to do it with WSSE:

http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html

Upvotes: 0

Related Questions