OAuth 2 explained theory
What is OAuth2
This protocol allows third-party applications to grant limited access to an HTTP service, either on behalf of a resource owner or by allowing the third-party application to obtain access on its own behalf. Access is requested by a client, it can be a website or a mobile application for example.
Roles
The Third-Party Application: "Client"
The client is the application that is attempting to get access to the user's account. It needs to get permission from the user before it can do so.
The API: "Resource Server"
The resource server is the API server used to access the user's information.
The Authorization Server
This is the server that presents the interface where the user approves or denies the request. In smaller implementations, this may be the same server as the API server, but larger scale deployments will often build this as a separate component.
The User: "Resource Owner"
The resource owner is the person who is giving access to some portion of their account.
Request details for a client application to access token .
Send a request to Google's OAuth 2.0 server.
o obtain user authorization, send a request to Google's authorization server at https://accounts.google.com/o/oauth2/v2/auth. This endpoint handles active session lookup, authenticates the user, and obtains user consent. The endpoint is only accessible over SSL, and it refuses HTTP (non-SSL) connections.
The authorization server supports the following query string parameters for installed applications:
client_id
redirect_uri -Required. Determines how Google's authorization server sends a response to your app. There are several redirect options available to installed apps, and you will have set up your authorization credentials with a particular redirect method in mind.
Sample url
https://accounts.google.com/o/oauth2/v2/auth? scope=email%20profile& response_type=code& state=security_token%3D138r5719ru3e1%26url%3Dhttps://oauth2.example.com/token& redirect_uri=com.example.app:/oauth2redirect& client_id=client_id
Exchange authorization code for refresh and access tokens
codeThe authorization code returned from the initial request. client_idThe client ID obtained from the API Console. client_secretThe client secret obtained from the API Console. This value is not needed for clients registered as Android, iOS, or Chrome applications. redirect_uriOne of the redirect URIs listed for your project in the API Console. grant_typeAs defined in the OAuth 2.0 specification, this field must contain a value of authorization_codePOST /oauth2/v4/token HTTP/1.1 Host: www.googleapis.com Content-Type: application/x-www-form-urlencoded code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7& client_id=your_client_id& client_secret=your_client_secret& redirect_uri=https://oauth2.example.com/code& grant_type=authorization_code
nice article
ReplyDelete