how can I authenticate a user from a web app to an API?

后端 未结 2 1068
面向向阳花
面向向阳花 2020-12-31 09:56

It seems to be a widely asked questions and after having read tons of documentations on the subject, I\'m still not sure to have understood everything correctly (I assume th

2条回答
  •  清酒与你
    2020-12-31 10:00

    You don't really want to login to the API using OpenID. As you said, OpenID is for Authentication, i.e. Who, while OAuth is for Authorization, i.e. am I allowed? But your structure suggest you'll be using an API as a backend and a web app as a front-end.

    The best way then is to use OpenID on the web-app to authenticate the user, and then the web-app connects to the API and stores the OpenID credentials. The web-app then knows who the user is, and can provide the service. The API has nothing to do with the user, except that it stores its data.

    The fundamental difference between OpenID and OAuth is its use. In your situation, you could have something like that:

    --------          ---------            -------
    | User | <------> |  App  | <--------> | API |
    --------  OpenID  ---------   (OAuth)  -------
    

    The User never interacts directly with the API: who would want to manually send HTTP request? (lol) Instead, the service is provided through the app, which can optionally be authorized using OAuth. However, in the case of a single app accessing the API, you can make the app <=> API connection internal and never expose it.

提交回复
热议问题