What is OAuth?
OAuth (Open Authorization) is an open standard for token-based authentication and authorization which is used to provide single sign-on (SSO).
OAuth allows an end user's account information to be used by third-party services, such as Facebook, without exposing the user's password.
It acts as an intermediary on behalf of the end user, providing the service with an access token that authorizes specific account information to be shared.
OAuth 1.0 vs. OAuth 2.0
|OAuth 1.0 used complicated cryptographic requirements.
||OAuth 2.0 is faster and easier to implement.
|It requires to encrypt the OAuth token on the endpoints.
||OAuth tokens no longer need to be encrypted on the endpoints in 2.0 since they are encrypted in transit.
|OAuth 1.0 only supported three flows, and did not scale.
||OAuth 2.0, on the other hand, has six flows for different types of applications and requirements, and enables signed secrets over HTTPS.
OAuth is a slightly newer standard that was co-developed by Google and Twitter to enable streamlined internet logins. OAuth uses a similar methodology as SAML to share login information. SAML provides more control to enterprises to keep their SSO logins more secure, whereas OAuth is better on mobile and uses JSON.Facebook and Google are two OAuth providers that you might use to log into other internet sites.
SAML vs. OAuth
|SAML uses XML to send Messages.
||OAuth uses JSON.
|SAML is more into enterprise security.
||OAuth 2.0 for Native and Mobile Apps.
|SAML uses session cookie in a browser that allows a user to access certain web pages.
||OAuth uses API calls extensively so mostly it used to provide a better experience in mobile applications, modern web applications, game consoles, and the Internet of Things (IoT) devices.
OAuth Protocol Flow Diagram:
OAuth - miniOrange OAuth Single Sign-On (SSO) Flow:
Let us take an example to show you how to implement OAuth as a Consumer:
REGISTER YOUR APP
Create an App in any OAuth Provider like Facebook, Twitter etc. After registering your application, you will receive a Consumer Key which identifies you to OAuth Provider.You will also receive a Consumer Secret that will be required when asking for an Request Token. Save the Consumer Key and Secret so that you can use it into your code as required.
GET A REQUEST TOKEN
The miniOrange Authentication Service requests a Request Token.The Request Token is a temporary token used to initiate User authorization for your application. The Request Token tells OAuth Provider that you've obtained User approval, but must be exchanged, along with the OAuth Verifier, for an Access Token.
GET USER PERMISSION TO ACCESS DATA
After getting the Request Token from OAuth Provider, miniOrange Authentication Service presents to your Users an authorization page asking them to give permission to our application to access their data.The authorization page will only ask for permission to a limited amount of User data, based on the access scopes you specified during the initial registration process.
EXCHANGE THE REQUEST TOKEN AND OAUTH VERIFIER FOR AN ACCESS TOKEN
After the users authorize miniOrange Authentication Service access to their information,our application needs to exchange the approved Request Token for an Access Token, which tells OAuth Provider that miniOrange Authentication Service has been given authorization to access User data.
AUTHENTICATE THE USER
After obtaining user information from the Access Token, it queries miniOrange Authentication Service enduser database. If the user already exists in database, it redirects to user Self Service Console. If the user does not exist in enduser database, it redirects back to Login Page.