DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
11 Monitoring and Observability Tools for 2023
Learn more
  1. DZone
  2. Data Engineering
  3. Data
  4. OAuth 2.0 Webapp Flow Overview

OAuth 2.0 Webapp Flow Overview

Roger Hughes user avatar by
Roger Hughes
·
Jul. 10, 12 · Interview
Like (0)
Save
Tweet
Share
4.12K Views

Join the DZone community and get the full member experience.

Join For Free
In my last few blogs I’ve been talking about accessing Software as a Service (SaaS) providers such as Facebook and Twitter using Spring Social. Some of you may have noticed that my sample code may have been a bit thin on the ground as I’ve being trying to describe what’s going on in the background and what Spring Social is doing for you.

So far I taken a bird’s eye view of OAuth defining it as the need for your application to get hold of an Access Token so that it can access your user’s private data from an SaaS provider without the need for your users to give your app their credentials. I’m concentrating on OAuth 2.0 and I’ve also hinted that before it can request an Access Token your app needs something called an Authorization Code, which it combines with its app secret.

This blog zooms in some more and hopefully explains what going on - at least in the case of OAuth 2.0.

One thing to remember about OAuth 2.0 is that there are six different flows covering different client scenarios such as the User-Agent flow and the Device Flow. This description covers the Web Server Flow for OAuth clients that are part of a web server application.

OAuth Steps in Summary

In summary, in the Web Server Flow, the following high level steps take place:

  1. The user logs into their SaaS provider
  2. Your application is sent an Authorisation Code
  3. Your application uses the Authorisation Code to retrieve an Access Token
  4. The Access Token is used to retrieve the user’s private data

For some, such a high level overview will suffice but, if you’re like me, then you’ll want to understand some of the nitty-gritty of what’s going on.

Obtaining an OAuth 2.0 authorisation token if often referred to as the ‘OAuth Dance’ and in this dance there are three dancers or actors:

OAuth Actors

Actor Description
User The user’s browser as controlled by a human user
TheApp The webapp that wants to access the user’s SaaS Data
SaaS App The Software as a Service provider such as Facebook

The OAuth Dance

The table below describes the OAuth 2.0 dance in detail...

ActorDescriptionData
User Navigates to TheApp in browser. TheApp in loading a page needs to ask for SaaS data  
TheApp TheApp has no AccessToken for this User on this SaaS provider and can't return the SaaS data.
It returns enough information to the User to allow him/her to request one.
authorize_url (The URL of the SaaS OAuth service)
redirect_uri
client_id (app key)
response_type: code
User The User contacts the SaaS provider asking for an Access Token Does a GET to the SaaS authorize_url passing the following params:
client_id: (app key)
redirect_url:
response_type: code
SaaS Responds with the User’s login page on the SaaS webapp  
User Types in their Username and Password on the SaaS site and presses okay. POSTs back SaaS login details such as user name and password
SaaS The SaaS provider asks user to confirm that TheApp can access their data.
It usually does this by presenting a small screen that asks something like: “Do you want TheApp to access your SaaS data?
This is REST so the following are carried through in hidden fields:
client_id: (app key)
redirect_url:
response_type: code
User Confirms the above to the SaaS client_id: (app key)
redirect_url:
response_type: code
authorize=1 (or YES)
SaaS The SaaS provider does not immediately create Access Token, instead it creates an authorization code
and stores it for later before passing it back to the User. The Access Token can then be requested and generated using this code.

The SaaS provider passes the code to the User as part of an HTTP redirect (Status codes 3xx).
The redirect is to TheApp’s redirect_url and contains:
code: (The authorisation code)
expires_in: (expiry time)
User Does a redirect using the URL from the last step back to TheApp with a GET request code: (The authorisation code)
expires_in: (expiry time)
TheApp TheApp then calls SaaS provider using a POST to retrieve the Access Token client_id (The App Id/Key)
client_secret
code
 (The App secret code)
redirect_url
grant_type: authorisation-code
SaaS The SaaS provider recognises the authorisation code and creates an Access Token.
It also revokes the authorisation code.
Returns the Access Token to TheApp
access_token (The prized Access Token)
expires_in (expiry time)
refresh_token
TheApp TheApp tells the user that the OAuth process has worked.  
TheApp TheApp can now access the User’s SaaS data using a GET request. Passes Access Token as HTTP authorization header (or request param) For example:
https://graph.facebook.com/me/friends?access_token=AAAAAAITEghMWiBBlEC5OG... etc ...eAVbjNnWjIlE
User The user now sees their SaaS data as displayed by TheApp in their browser  

In the table above I've included many of the data parameters that are carried through from request to request, even though they are always needed at that point in the sequence. The thing to remember here is that for very practical reason a SaaS provider is a REST service and therefore doesn't maintain state between client requests.

A final point to note here is that all this takes place using SSL to ensure that keys, secrets, codes etc are hidden from prying eyes.

A really good way of seeing all this in action is to create a Hootsuite account and use it to access your Twitter, Facebook, LinkedIn etc data: all the screens popup in all the right places: probably a classic implementation.
SaaS authentication security Flow (web browser) Data (computing) app Web server Requests

Published at DZone with permission of Roger Hughes, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Little's Law and Lots of Kubernetes
  • 10 Easy Steps To Start Using Git and GitHub
  • How To Build an Effective CI/CD Pipeline
  • Using GPT-3 in Our Applications

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: