3

This is in relation to my other question about the need to create a Facebook app.

I've been reading a lot about how to best approach login for mobile apps users (iOS and Android) that access my web service running on Google App Engine. I'm still not clear how to best do it as I would like to offer login with both Google and Facebook. The app and the web service does nothing with Facebook or Google other than I would like to piggyback on their login.

Having only login with Google for GAE is very easy and the same goes for using OpenIDConnect. Facebook unfortunately does not support this.

Reading an old question here on SO where someone wanted to do the same as I it looks like the app should do Facebook Login and then get a token that it passes to my backend which needs to be validated by contacting Facebook. Is this how to do it today?

I also found Google Identity Toolkit, which seem to be what I need. However, I do not have a website or just apps. I would need to have the apps do the Facebook login and somehow provide my web service with something so it can validate the login info.

Later on an app user should be able to log in using randomly Facebook, Google and my custom username/password. The app and the web service should know the user is logged in and authorize it to access the REST API.

How do I accomplish this? BTW, I'm using Go on GAE.

I would really appreciate if someone could explain if there are several options how to do this, pros and cons, and provide an overview of the best approach and what needs to be done.

Many thanks for any help with this!

UPDATE

OK, thanks a lot everyone for the help and pointers. I have successfully run the quickstart sample app for iOS for my GAE backend. Basically, created a Facebook app and permissions credentials on my web service on GAE so that the sample iOS app can log in.

A bit of a gap still before I have an authenticated user in the datastore and can authorize successive API calls.

Main open questions at this point:

  1. how to get the gtoken in the iOS app after successful Facebook or Google login?
  2. should I explicitly call an API on my web service to pass in the gtoken or is this somehow automatic with Gitkit API enabled?

Thanks for any help!

UPDATE

To answer #1 and #2 myself, there's a "successful sign-in url" that can be given in the app engine config so the app knows where to call with the gtoken. Then after that it's like explained in the answers.

Community
  • 1
  • 1
murrekatt
  • 5,961
  • 5
  • 39
  • 63
  • 1
    *which needs to be validated by contacting Facebook.* why validate it? You made the app, you already know where the token came from and whether it's valid or not – Tim Aug 26 '15 at 07:20
  • @TimCastelijns could you maybe provide a more elaborate answer? Yes, the app is in my control but any other program might also access my API. – murrekatt Aug 26 '15 at 07:33
  • Oh ok, I wasn't aware this would be a public api, sorry – Tim Aug 26 '15 at 07:39

2 Answers2

6

Looks like you have an app and a backend on GAE. If you are using google identity toolkit, it will allow you to signin with Facebook, Google, and email/password.

When user successfully signs in to your app using identity toolkit, your server should receive a gtoken. You have two options here:

  1. Pass the gtoken to your app and save it there. When your app makes API calls to your backend, you app should attach the gtoken to every request. Your backend should verify the gtoken(https://developers.google.com/identity/toolkit/web/required-endpoints) for every API that needs authorization.
  2. Verify the gtoken, generate a token that your backend can recognize/identify the user. Then pass the token to your app and everything else is the same as option 1.

If you do not want to use identity toolkit, you can implement facebook login on your app/backend and use facebook token to communicate between your app and backend.

Whatever your decision is, apps that use your API should pass you something that your backend can recognize/authorize the user.

Ying
  • 76
  • 1
  • Thanks @Ying for the answer. It sounds like I do not want to pass the gtoken around as it's too heavy to validate, and it also doesn't seem good to pass Facebook tokens around as I would like to have a federated login. Hence, option number 2 seems best. – murrekatt Aug 26 '15 at 21:26
3

The answer is about using Google Identity Toolkit (GIT). GIT itself is an identity provider, which would be integrated with your apps and backend. The flow works along these lines:

  • your app requests login via its GIT API
  • GIT will perform the federated login with Facebook or other 3rd party provider (transparent to your app) and returns a GIT token to the app (representing a unique user from your end-to-end system perspective, i.e. apps plus backend)
  • the app makes a request to the backend in which it passes the GIT token
  • the backend verifies the GIT token validity (using this go GIT client API, for example) and from it can extract the identity of the user and thus validate the request

You can find more detailed info about the backend token validation in the backent endpoint doc, look for these sections in particular:

  • Understanding the Identity Toolkit cookie/token
  • Getting information for users

Now the actual token validation on the backend may take a few seconds, so it might not be practical to do it for each and every REST request from the app. If so you'd need to somehow:

  • save the info that the user of that specific app instance is authenticated in something like a "session" managed between your app and the backend
  • map a specific REST request received by the backend to a specific such authenticated "session"

But I'm not sure how exactly is this "session" functionality done in the apps+backend context, I didn't write any apps yet.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97