OAuth is an open standard to authorization. OAuth provides client applications a secure delegated access to server resources. OAuth 2.0 defines four roles:
+--------+ +---------------+
| |--(A)- Authorization Request ->| Resource |
| | | Owner |
| |<-(B)-- Authorization Grant ---| |
| | +---------------+
| |
| | +---------------+
| |--(C)-- Authorization Grant -->| Authorization |
| Client | | Server |
| |<-(D)----- Access Token -------| |
| | +---------------+
| |
| | +---------------+
| |--(E)----- Access Token ------>| Resource |
| | | Server |
| |<-(F)--- Protected Resource ---| |
+--------+ +---------------+
Source: RFC 6749
Many services such as Facebook, Github, and Google have already deployed OAuth 2 servers, and deployed implementations. Before you can begin the OAuth process you must first register a new app with the service (Google, Facebook etc.). When registering a new app, you usually fill some basic information such as application name, website, logo etc. In addition you must register an URI used for redirecting users within web server, browsed-based, or mobile apps.
After registering your app, you will receive a client ID and a client secret. The client ID is considered public information, and is used to build login URLs, or included in Javascript source code on a page. The client secret must be kept confidential. If a deployed app cannot keep the secret confidential, such as Javascript or native apps, then the secret is not used.
The first step of OAuth 2 is to get authorization from the user. For browser-based or mobile apps, this is usually accomplished by displaying an interface provided by the service to the user. Web server apps are the most common type of application you encounter when dealing with OAuth servers. Web apps are written in a server-side language and run on a server where the source code of the application is not available to the public. You must prepare valid "Log in" link sending to the user. After clicking you will see something like an authorization prompt with question similar to "An application would like to connect to your account...allow app access? DENY/ALOW". If user clicks "Allow", the service redirects the user back to your site with an auth code. After that your server exchanges the auth code for an access token. Server replies with an access token and that's all. As long as token is up to date you can use your app.