2. Client-Server Authentication Model
In the traditional client-server authentication model,
the client requests an access-restricted resource (protected
resource) on the server
by authenticating with the server using the resource owner’s
credentials.
In order to provide third-party applications access to restricted
resources,
the resource owner shares its credentials with the third party.
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 2 / 17
3. Problems and limitations
This creates several problems and limitations1
:
Third-party applications are required to store the resource owner’s credentials for future use, typically a password in
clear-text.
Servers are required to support password authentication, despite the security weaknesses inherent in passwords.
Third-party applications gain access to the resource owner’s protected resources, leaving resource owners without any
ability to restrict duration or access to a limited subset of resources.
Resource owners cannot revoke access to an individual third party without revoking access to all third parties, and
must do so by changing the third party’s password.
Compromise of any third-party application results in compromise of the end-user’s password and all of the data
protected by that password.
In OAuth, the client requests access to resources controlled by the resource owner and hosted by the resource server,
and is issued a different set of credentials than those of the resource owner.
1
https://tools.ietf.org/html/rfc6749
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 3 / 17
4. OAuth 2.0
OAuth defines four roles:
Resource Owner
Client
Resource Server
Authorization Server
Figure: Abstract Protocol View
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 4 / 17
5. OAuth 2.0
OAuth addresses these issues by introducing an authorization
layer and separating the role of the client from that of the
resource owner.
The OAuth 2.0 authorization framework enables a third-party
application to obtain limited access to an HTTP service, either
on behalf of a resource owner by orchestrating an approval
interaction between the resource owner and the HTTP service,
or by allowing the third-party application to obtain access on its
own behalf.
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 5 / 17
6. OAuth 2.0 : Working
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 6 / 17
7. OAuth 2.0 : Steps
A : The client requests authorization from the resource owner.
B: The client receives an authorization grant, which is a
credential representing the resource owner’s authorization
C: The client requests an access token by authenticating with
the authorization server and presenting the authorization grant.
D: The authorization server authenticates the client and
validates the authorization grant, and if valid, issues an access
token.
E: The client requests the protected resource from the resource
server and authenticates by presenting the access token.
F: The resource server validates the access token, and if valid,
serves the request.
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 7 / 17
8. Application Registration
Before using OAuth with your application, you must register your
application with the service. This is done through a registration
form in the “developer” or “API” portion of the service’s website
-Application Name
-Application Website
-Redirect URI or Callback URL
The redirect URI is where the service will redirect the user after
they authorize (or deny) your application, and therefore the part
of your application that will handle authorization codes or access
tokens.
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 8 / 17
9. Client ID and Client Secret
the service will issue “client credentials” in the form of a client
identifier and a client secret.
The Client ID is a publicly exposed string
that is used by the service API to identify the application, and is
also used to build authorization URLs that are presented to
users.
The Client Secret is used to authenticate the identity of the
application to the service API when the application requests to
access a user’s account, and must be kept private
between the application and the API.
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 9 / 17
10. Authorization Grant
OAuth 2 defines four grant types, each of which is useful in different
cases:
Authorization Code: used with server-side Applications
Implicit: used with Mobile Apps or Web Applications
(applications that run on the user’s device)
Resource Owner Password Credentials: used with trusted
Applications, such as those owned by the service itself
Client Credentials: used with Applications API access
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 10 / 17
11. Authorization Grant: Authorization Code
1. Authorization Code Link
First, the user is given an authorization code link that looks like
the following:
https://cloud.digitalocean.com/v1/oauth/authorize?
response_type=code&client_id=CLIENT_ID&redirect_
url=CALLBACK_URL&scope=read
client id=client id: the application’s client ID (how the API
identifies the application)
redirect uri=CALLBACK URL: where the service redirects the
user-agent after an authorization code is granted
response type=code: specifies that your application is requesting
an authorization code grant
scope=read: specifies the level of access that the application is
requesting
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 11 / 17
12. Authorization Code
Step 2: User Authorizes Application
When the user clicks the link, they must first log in to the
service, to authenticate their identity (unless they are already
logged in). Then they will be prompted by the service to
authorize or deny the application access to their account.
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 12 / 17
13. Authorization Code
Step 3: Application Receives Authorization Code
If the user clicks “Authorize Application”, the service redirects
the user-agent to the application redirect URI, which was
specified during the client registration, along with an
authorization code. The redirect would look something like this
(assuming the application is “dropletbook.com”):
https:
//dropletbook.com/callback?code=AUTHORIZATION_CODE
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 13 / 17
14. Authorization Code
Step 4: Application Requests Access Token
The application requests an access token from the API, by
passing the authorization code along with authentication details,
including the client secret, to the API token endpoint. Here is
an example POST request to DigitalOcean’s token endpoint:
https://cloud.digitalocean.com/v1/oauth/token?
client_id=CLIENT_ID&client_secret=CLIENT_SECRET&
grant_type=authorization_code&code=AUTHORIZATION_
CODE&redirect_uri=CALLBACK_URL
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 14 / 17
15. Authorization Code
Step 5: Application Receives Access Token
If the authorization is valid, the API will send a response
containing the access token (and optionally, a refresh token) to
the application. The entire response will look something like this:
"access_token":"ACCESS_TOKEN","token_type":
"bearer","expires_in":2592000,"refresh_token":
"REFRESH_TOKEN","scope":"read","uid":100101,"info":
{"name":"MarkE.Mark","email":
"mark@thefunkybunch.com"}
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 15 / 17
16. Homework: Authorization Code a
a
https://www.digitalocean.com/community/tutorials/
an-introduction-to-oauth-2
Implicit
Resource Owner Password Credentials
Client Credentials
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 16 / 17
17. Homework for Lab
OAuth 2.0 Java Guide: Secure Your App in 5 Minutes
https:
//developer.okta.com/blog/2019/10/30/java-oauth2
Spring Boot and OAuth2
https:
//spring.io/guides/tutorials/spring-boot-oauth2/
Implementing The OAuth 2.0 Authorization Framework Using
Jakarta EE
https:
//www.baeldung.com/java-ee-oauth2-implementation
Dr.Ramchandra Mangrulkar Lecture #25: OAuth 2.0 September 23, 2020 17 / 17