On Tue, Jul 8, 2014 at 4:47 PM, Fernando Arconada
<
fernando...@gmail.com> wrote:
> Having a REST backend and Phonegap app, how do you use to register your
> mobile users?
> a) Register via API, uhmmm is it secure? It could be dangerous if it's
> scriptable
I use OAuth in this case. First you have to create user. So make a
POST request to "/users" and use OAuth client credentials grant type.
It is secure, because you need client credentials.
Next your user is created, so you can generate access token using
resource owner password credentials grant type and you receive access
token as a result. You can use this type of grant, because you own
your mobile app, so it is trusted.
Now you have access token and you can make API requests.
> b) HWI bundle to able to login with Facebook, Gmail.... but how the app
> knows your credentials? OAUTH? is my OAUTH Server necessary? and with WSSE?
My approach:
First you have to register user. So you generate OAuth access token on
mobile app and send it to your API. Because users is not created yet,
use client credentials grant type. On API side use this token to fetch
user credentials from third-party service (Facebook, LinkedIn, etc.)
and create user in your database using this credentials (facebook_id
user property for example).
When you want to log in, you have to generate access token in your
OAuth server. So first generate third-party access token on mobile app
("Log in with Facebook") and than use it to generate access token in
your OAuth server. So on API side use third-party access token again
to fetch user credentials form third-party service and than find user
with those credentials in your database. If they match, then you've
found your user and you can generate access token for him. This is not
possible in FOSOAuthServerBundle, so I've created my own controller
which does this.
If you have existing user and you want to be able to login with
third-party credentials, again generate third-party access token on
mobile ("Connect with Facebook") and add third party credentials to
your user (facebook_is property for example). You will be able to log
in using the same flow as above.