Cyril N.
Cyril N.

Reputation: 39889

Restful API, how an app can (re)match a user to an existing one?

I asked various questions about my problem (here and here) and I also asked in the #oauth & #openid freenode's channel on IRC. (this is note an "UP" question, it's an other problem)

I'll sum up my project configuration : Anyone will have the possibility to create an app that can use my API. To start, I'll work on my API and a Web based app, but the documentation about the API will be public. It's a bit like Twitter API.

The problem I face is how can I be sure which user is using the API (to retrieve his personal data, like your tweets), even if the User is using an app that I don't know who make it (again, like twitter and all the apps around).

I googled a lot and with the help of the previous answers given, I took a look at OAuth.

As far as I understood the way OAuth works, here how :

So far, everything goes well. But what I can't figure it out, is when the user quit the app and goes again : how the app can remember the user is the one that used it before ?

(Before some of you bring me the cookie answer, I'll remark this is a simple example, it would be the same if the user clear his cookies, format his computer or change its computer.)

The only solution I can find, is when an unauthenticated user (without a remembering cookie for example) goes to the app, the app redirect him again to the API to authenticate himself, but this time, the user won't have to re-allow the app (authorization) since it already did it. The API will then return the user to the app to allow him to play with this.

Is this the proper & secure way to do it ?

The #OAuth IRC channel told me about the new protocol, WebID, but this is currently in pre-draft mode and I don't want to use something that will change continuously in the future :/

Thank you very much for your help!

Upvotes: 0

Views: 535

Answers (2)

Cyril N.
Cyril N.

Reputation: 39889

if we take a look at how Twitter works, I think the missing point is an other layer to the project: The Official website:

alt text

The thing is, when you want to allow any 3rd party application to use Twitter, this application redirect you to the OAuth page of the Twitter API, IF you are connected, but if you aren't, it redirect you to the login page, which is located at http://api.twitter.com/login (I don't know if keeping the api in api.twitter.com for loging an user, instead of just twitter.com is correct, but this is just semantics)

So, the workflow would be:

  • A user goes to a 3rd party application (like a website)
  • This third party redirect the user to the API for Authorization
  • The API redirect the User to the website for Authentication first
  • The official website redirect the User to the OpenId provider (or Facebook connect)
  • The Authentication is made (via multiple requests)
  • The website redirect the user to the API after he's successfully authenticated
  • The user allow/disallow the permissions asked by the 3rd party apps
  • The API returns to the 3rd party apps.
  • The User can now use (or not) the application.

This implementation have 2 problems:

  • Every time an User ins't authenticated (cleared it's cookies, connect himself from an other computer, etc), he will have to go through the Authentication method, by being redirected to the Official website and then being redirected to the 3rd party application (the API would be transparent, since it has already allowed the application to access his data).
  • All those layers would certainly lost the User on the Authentication process with too many redirections.
  • A possible solution would be to store the user's access_token, for example in the case of a mobile app, but with a pure html/css/js oriented app, this isn't possible. A login/password in the 3rd party web application that would match the user to the access_token of the API would be an other solution, like Seesmic (I think), but this is just useless (for us, not Seesmic) : the idea of not having the user's password become useless.

This is a possible explanation but I would require more details on how this is possible and your thought about that solution. Would it work?

(I added this as an answer since it's an (incomplete and not so sure, I agree) one.

Upvotes: 1

Jon Nylander
Jon Nylander

Reputation: 8963

Short answer: OAuth results in an authenticated access token. That access token is tied to ONE user. And as long as the access token is valid. The third application can do whatever the API allows the access token to do.

Long answer: The thing with OAuth is that it does not "Log in" a user. OAuth gives third party applications what is called access tokens which can be used to access data on behalf of a user whether he/she is logged in or not.

Many services restrict their access tokens. Twitter for example issues two types of access tokens, read-only, and read/write. But there is no concept of logging in to use APIs. While an access token is valid, a third party application can access the user's data, and change things without a user's explicit interaction.

Most API providers have functionality to revoke access tokens. That is what happens when you in twitter look at your Connections page . See the revoke access links? Revoking access to apps in Twitter

Personally I love the OAuth approach. As an API provider, you can control what access tokens are allowed to do, and the user can kill bad applications from using his/her resources. OAuth is secure as far as authentication goes. Third party applications do not get hold of user's passwords. But once authenticated they can do whatever your API allows.

Upvotes: 1

Related Questions