What is OAuth?
OAuth is a protocol that allows distinct parties to share information and resources in a secure and reliable manner.OAuth needs to consider the 2 concept to provide the informations in secure and reliable manner. They are authentication and authorization.
- Authentication -> Validating the person/system who need the information
- Authorization -> After authentication what action can be performed by the person/system.
- Federated identity -> User can use his/her one application account to login another application.
- Delegated identity -> One service can access another service resources.
OAuth can be build in 4 steps
- Register your client application
- Get your access token [using client side flow/server side flow]
- Use your access token to access a protected resource
- If applicable refresh your access token [server side flow -access token expired use the refresh token to get new access token]
Register your client application
- Client ID -> Application unique identifier. [client name can be duplicated and name is for the human readings]
- Client Secret -> Secret key use by the application to identify itself when making requests.
- Redirection Endpoint -> The endpoint which is used by the service providers to send you response. [tokens/errors]
- Authorization endpoint -> An endpoint which uses by the client app to initiate the authorization flow. [this will be determined by the service provider]
- Token endpoint -> Endpoint use to initiate the token flow by the client application. [This will also determined by the service providers]
Get your access token
After the app registration we can fetch the access token. When accessing the access token our application can be considered as trusted and untrusted application. If our application is trusted, then our app could use authorization code grant flow. If our application is untrusted, then it could use implicit grant flow.Access token has 2 properties known as scope and duration of access respectively.
- Scope -> what are the protected information can be accessed by the token holder. [This scope can cover a wide range of protected resources, such as the ability to read and modify any data with a particular user's account, or it can be as fine-grained as the ability to only fetch the first name of a given user]
- Duration of access -> Time limit of access to the protected information. [perpetual token - no time expiration]
- Token revocation -> In some certain cases we have need to terminate the access before it expires. [revoking the access]
- Refresh token -> Token which is refreshing the session by requesting a new access token when the current one expired.
Use your access token
After get the access token, then we can make API-Application program interface calls. [API differ according to their services, but the way passing the access token will remain same]There are multiple ways to pass the token, they are authorization request header field, form encoded body parameter and URI query parameter. [Example: After getting the access token from the Facebook access token holder can make the call to Facebook Graph API to get the user’s protected information]
Refresh your access token
Most of the access tokens are having expiration periods. Once it expires, it can not use to access the user’s protected information. So, to continue to access protected resources there are 2 options.- Do the authentication process again. [Start from the initial step]
- By using refresh access token to establish new session by getting new access token.
Comments
Post a Comment