What's the difference between OpenID and OAuth?

后端 未结 21 733
渐次进展
渐次进展 2020-11-22 16:56

I\'m really trying to understand the difference between OpenID and OAuth? Maybe they\'re two totally separate things?

相关标签:
21条回答
  • 2020-11-22 17:13

    Use OAuth if your users might just want to login with Facebook, or Twitter. Use OpenID if your users are neckbeards that run their own OpenID providers because they "don't want anyone else owning their identity".

    0 讨论(0)
  • 2020-11-22 17:13

    I'd like to address a particular aspect of this question, as captured in this comment:

    OAuth: before granting access to some feature, authentication must be done, right ?. so OAuth = what OpenId does + grants access to some features ? – Hassan Makarov Jun 21 at 1:57

    Yes... and no. The answer is subtle, so bear with me.

    When the OAuth flow redirects you to a target service (the OAuth provider, that is), it is likely that you'll need to authenticate with that service before a token will be handed back to the client application/service. The resulting token then allows the client app to make requests on behalf of a given user.

    Note the generality of that last sentence: specifically, I wrote "on behalf of a given user", not "on behalf of you". It's a common error to assume that "having a capability to interact with a resource owned by a given user" implies "you and the owner of the target resource(s) are one in the same".

    Don't make this mistake.

    While it's true that you authenticate with the OAuth provider (say, by user name and password, or maybe SSL client certs, or some other means), what the client gets in return should not necessarily be taken as proof of identity. An example would be a flow in which access to another user's resources was delegated to you (and by proxy, the OAuth client). Authorization does not imply authentication.

    To handle authentication, you'll likely want to look into OpenID Connect, which is essentially another layer on top of the foundation set by OAuth 2.0. Here's a quote that captures (in my opinion) the most salient points regarding OpenID Connect (from https://oauth.net/articles/authentication/):

    OpenID Connect is an open standard published in early 2014 that defines an interoperable way to use OAuth 2.0 to perform user authentication. In essence, it is a widely published recipe for chocolate fudge that has been tried and tested by a wide number and variety of experts. Instead of building a different protocol to each potential identity provider, an application can speak one protocol to as many providers as they want to work with. Since it's an open standard, OpenID Connect can be implemented by anyone without restriction or intellectual property concerns.

    OpenID Connect is built directly on OAuth 2.0 and in most cases is deployed right along with (or on top of) an OAuth infrastructure. OpenID Connect also uses the JSON Object Signing And Encryption (JOSE) suite of specifications for carrying signed and encrypted information around in different places. In fact, an OAuth 2.0 deployment with JOSE capabilities is already a long way to defining a fully compliant OpenID Connect system, and the delta between the two is relatively small. But that delta makes a big difference, and OpenID Connect manages to avoid many of the pitfalls discussed above by adding several key components to the OAuth base: [...]

    The document then goes on to describe (among other things) token IDs and a UserInfo endpoint. The former provides a set of claims (who you are, when the token was issued, etc, and possibly a signature to verify the authenticity of the token via a published public key without having to ask the upstream service), and the latter provides a means of e.g. asking for the user's first/last name, email, and similar bits of info, all in a standardized way (as opposed to the ad-hoc extensions to OAuth that people used before OpenID Connect standardized things).

    0 讨论(0)
  • 2020-11-22 17:16

    OpenID is (mainly) for identification/authentication, so that stackoverflow.com knows that I own chris.boyle.name (or wherever) and therefore that I am probably the same person who owned chris.boyle.name yesterday and earned some reputation points.

    OAuth is designed for authorization to take actions on your behalf, so that stackoverflow.com (or wherever) can ask permission to, say, Tweet on your behalf automatically, without knowing your Twitter password.

    0 讨论(0)
  • 2020-11-22 17:18

    I have read a lot of articles on this topic and found below link very useful to distinguish OpenId and OAuth. Basically we need to understand difference between id_token and access_token. This will help in distinguishing OpenId Authentication and OAuth Authorizarion.

    My conclusion:

    id_token = JWT Token

    access_token = GUID string

    https://nhsconnect.github.io/national-authentication/TechOverview_Artefacts.html#:~:text=A%20JSON%20Web%20Token%20(JWT,used%20during%20the%20authentication%20service.&text=An%20access%20tokens%20is%20a%20credential%20used%20to%20access%20protected%20resources.
    
    
    https://www.youtube.com/watch?v=BdKmZ7mPNns
    

    Youtube link OpenId time start: 08:10

    Hope this well help.

    0 讨论(0)
  • 2020-11-22 17:25

    At finally OAuth gives you back the access token to access the resource from resource server, OpenID gives you back meta data details about resources in JWT / encrypted token

    0 讨论(0)
  • 2020-11-22 17:26

    OpenID proves who you are.

    OAuth grants access to the features provided by the authorizing party.

    0 讨论(0)
提交回复
热议问题