OAuth 2.0 framework
OAuth Authorization Server and an OAuth Resource Server
What is OAuth?
OAuth is an open standard for access delegation, commonly used as a way for Internet users to grant websites or applications access to their information on other websites but without giving them the passwords.
OAuth 2.0 - OAuth 2.0 is not backwards compatible with OAuth 1.0. OAuth 2.0 provides specific authorization flows for web applications, desktop applications, mobile phones, and smart devices. The specification and associated RFCs are developed by the IETF OAuth WG the main framework was published in October 2012.
There are four types of roles in OAuth,
- Client
- Resource Owner(User)
- Resource Server
- Authentication Server
- Authorization Code Grant Type - The Authorization Code grant type is used by confidential and public clients to exchange an authorization code for an access token.
- Implicit grant type - The Implicit grant type is a simplified flow that can be used by public clients, where the access token is returned immediately without an extra authorization code exchange step.
- Password grant type - The Password grant type is used by first-party clients to exchange a user's credentials for an access token.
- Refresh Token grant type - The Refresh Token grant type is used by clients to exchange a refresh token for an access token when the access token has expired.
In this blog post, we are going present how to do some actions with OAuth 2.0 token
This implementation contains,
- Send a request to the OAuth authorization server website for obtaining the access token.
- Once the OAuth access token is received, invoke the resource server APIs and obtain the protected resources or perform the particular action.
For an example we are going to develop a web application to upload files to google drive.
Let's see this source code....
This has implement using Angular CLI
We can get a access token by using above code. In this scenario, we have get the token and save it in a cookie.
Here we have to add extra scope to get access to Google Drive.
Scope URL - https://www.googleapis.com/auth/drive.file
After add the scope in the code we have to add the same scope URL in the Credential as well.
We have to click Add scope button and enter above mention URL and submit it.
By click Upload button user can upload a file to Google Drive. In upload.component.ts get the uploaded file and set as a Blob file. And also we can set a filename, mimeType at Google Drive. Before upload a file into Drive we have to create a folder manually and set the folder id in parents field. Then we have to set the authorization header. For authorization header we have to pass the access token that we have previously receive.
POST : https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart
Here is the link to clone source code through the GitHub
Comments
Post a Comment