Which is the better way to implement authenticatio

2019-07-23 06:28发布

问题:

I'm gonna try to explain my problem :

I'd like to allow users to connect to my api via their own accounts (login/password) or via a social network (Facebook at first).

Then, I would allow any application to use my api, with the user authenticated.

My first thought when to auth the user via his/her login/password and return a token used as the session for the next requests.

But OAuth would seems to be the better implementations, except I don't know how to do this :

  • One of my applications will have to connect via login/password, like twitter web (I have to implement an login/password auth somewhere if I wan't my user to login :p)
  • Will I also have to register my applications to the oauth system (did twitter added their web app to their oauth ?)
  • How to merge the auth via others social networks. Concretely, the user will have to OAuth to my api that will auth to the social network.

I'm a bit lost on how to do this, if someone could help me, I would really appreciate !

Thanks

Update 1: Flickr and Lastfm seems to not use OAuth but an alternative auth system that looks like this :

  • The user is redirected to Flickr/Lastfm
  • The user auth himself and accept to use the application
  • Flickr/Lastfm return to the Callback url with a temporary frob (for flickr) or token (for lastfm)
  • The app must call the provider with the temporary frob/token (among with the api_key and the api_sig, as always) and get in return the session token to use for the next calls.

Update 2: In fact, StackApps is the concrete case of my problem : you can login through their login/password system OR openId, and you can use their API.

回答1:

OAuth is only needed to make others use your API on other services, i.e. authorize services to use your API without users of the intermediary service explicitly having to log in into your service by giving user's login credentials to a third party.

What I think you need is OpenID, the cross-application authentication mechanism. You just need to implement an OpenID client, accepting third-party OpenIDs to authenticate users, to subsequently identify them, when they use your service's API. This would have to be supplemented with a normal 'local' user authentication mechanism (i.e. login/password entry page)

You will need OAuth to provide an ability to use your API on other sites, though.