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 Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Securing REST APIs With Nest.js: A Step-by-Step Guide
  • Securing RESTful Endpoints
  • What Is API-First?
  • Leveraging Salesforce Using Spring Boot

Trending

  • Identity in Action
  • Building a Spring AI Assistant With MCP Servers: A Step-by-Step Tutorial
  • Slopsquatting: Building a Scanner That Catches AI-Hallucinated Packages Before They Reach Production
  • Building Threat Intelligence Pipelines Using Python, APIs, and Elasticsearch
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Authentication and Authorizing for WebService/REST API Calls

Authentication and Authorizing for WebService/REST API Calls

Follow this overview of how the concerns of Authentication and SSO come together to plug into Authorization (mainly in the scope of API authorization).

By 
Ravi Kiran Mallidi user avatar
Ravi Kiran Mallidi
DZone Core CORE ·
Kiran Kumar A user avatar
Kiran Kumar A
·
Aug. 15, 22 · Analysis
Likes (4)
Comment
Save
Tweet
Share
7.1K Views

Join the DZone community and get the full member experience.

Join For Free

The purpose of this article is to be an overview of how the concerns of Authentication and SSO come together to plug into Authorization (mainly in the scope of API authorization). Application Architectures utilize industry standard protocols and patterns necessary to work together in all applications such as B2C, B2B, and B2E. The primary audience of this document is application architects and application security architects. However, those in the Identity and Access Management space will also find the concepts presented here apply to them.

Web Application and Mobile Thick Client Authentication Strategy

User Authentication and Authorization across web applications (both mobile and non-mobile) for all application realms (B2C, B2B, and B2E) should focus on SSO (Single-Sign-On). Web applications authenticate users using an Identity Provider that supports the standard like SAML2 and OAuth2. In addition, all mobile (Phone or Tablet) thick applications should authenticate their users by utilizing an Identity Provider that supports the industry standard OAuth2 Protocol. 

JWT: JSON Web Tokens

JSON Web Token (JWT) is a JavaScript object notation that is a representation format for HTTP HTTP Authorization headers and query parameters. JSON is used in REST API payload along with JSON Web Signature (JWS) structure or as the plaintext of a JSON Web Encryption (JWE) structure for enabling the claims to be digital. JWTs are always represented using the JWS / JWE Compact Serialization. JWT works by simply encoding a string made up of a small JSON object and hashing it using a secret shared between the two parties. The algorithm is configurable but is usually HMAC SHA-256. JWT does not encrypt the payload, and it only signs it.

Web Application Authentication and SSO

The industry standard-based approaches for web application authentication and SSO center around two protocols.

  • SAML 2.0
  • OAuth2

OAuth2 protocol was initially widely adopted by large social sites (Facebook, Google, Twitter, etc.) for authentication as they have taken OAuth2 and created proprietary SSO mechanisms. As a result, users can go back and forth between their applications after being authenticated while using their APIs. While SAML 2.0 enjoys wide adoption in old applications for authenticating REST/JSON overtook SOAP/XML. Nowadays, all the applications are adopting OAuth2 as a standard.

OAuth 2 Access Tokens

RESTful APIs are secured using OAuth2. Expect an OAuth2 access token to be provided by the caller. The access token provided by the caller should only be passed as an Authorization HTTP Header such as:

  • Authorization: Bearer access_token

Clients interact with RESTful APIs over HTTPS/SSL, and the contents of the HTTP Headers and thus the access token is encrypted. Therefore, passing OAuth2 access tokens via query parameters such as below is prohibited as standard because the access token, which must be kept secret, is exposed in transit and appears in web server logs. 

  • https://<<URL>>/profile?access_token=MzJmNDc3M2VjMmQzN

So, the critical point is that the clients must obtain an OAuth2 access token for interacting with RESTful APIs. There are several ways to get tokens depending on the type of application, the authorization source involved, if an SSO approach is employed, etc. All of these approaches require communication with the OAuth2 Authorization Server. It is essential to understand that the OAuth2 framework does not provide SSO. 

Roles in OAuth2

  • Resource Owner - This is the user using the application and owns/has rights to access the data provided by the resource server. They authorize a client application to access back-end data.
  • Resource Server - The server where the RESTful APIs are exposed. 
  • Client Application - The application requesting access to a resource server. It can be a traditional web application, a JavaScript (Single Page Application or SPA) application, or a mobile application.
  • Authorization Server - The server issues an access token to the client. The client uses these tokens to request access to the resource server. 

Roles in OAuth2

OAuth2 REST API Access

The web application needs to access RESTful APIs, and the web application already possesses an access token delivered along with the JSON Web Token (JWT) when the user is authenticated. Since OAuth2 requires authentication to provide an access token, and the application already has the access token due to user authentication, the two come together using this pattern. This applies to all web applications where both are used and a user has already logged in. OAuth2 compliant authorization servers return a JWT with user claims at the OAuth 2.0 token validation endpoint. OAuth2 Connect compliant identity servers return a JWT containing the user claims. OAuth2 compliant authorization servers can return a JWT or JSON as the user info endpoint response.

 

It is always a good idea to expose to secured SSL and TLS channels for all REST APIs. Finally, OAuth2 is a widely used authentication of REST APIs in microservices architectures using JWT token mechanism.

API REST authentication

Opinions expressed by DZone contributors are their own.

Related

  • Securing REST APIs With Nest.js: A Step-by-Step Guide
  • Securing RESTful Endpoints
  • What Is API-First?
  • Leveraging Salesforce Using Spring Boot

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook