Urgent.News

What's breaking now, across thousands of outlets.

Tech

Secure Your APIs: OAuth2 and JWT for Beginners

Repository with the companion code for the tutorial APIs are frequent targets for bad actors since they expose data and functionality. Securing them while maintaining usability is often one of the most challenging and time-consuming parts of API development. OAuth 2.0 and JSON Web Tokens (JWT) help make these processes more manageable and reliable. They allow developers to represent and verify…

In the digital landscape, APIs are prime targets for malicious actors due to their exposure of valuable data and functionality. Securing these interfaces while preserving usability can be a complex and time-consuming endeavor. OAuth 2.0 and JSON Web Tokens (JWT) are tools that simplify and enhance this process by managing identity, access, and delegation efficiently.

OAuth 2.0 and JWT are not competing technologies; instead, they complement each other. OAuth 2.0 handles delegation of authorization, while JWT provides a compact, verifiable token format to securely transmit secure information. Authentication (verifying identity) and authorization (controlling access) are two distinct concepts. While JWTs can include identity information and function as an ID once issued, they also carry roles and other claims used for authorization.

The OAuth 2.0 framework manages delegated access, allowing users to grant applications tokens that represent their permissions without directly sharing passwords. This decoupling simplifies APIs and reduces security risks by allowing backends (acting as Resource Servers) to trust and validate tokens issued by an Authorization Server rather than handling user logins or browser redirects themselves.

JSON Web Tokens (JWT) are compact, web-friendly pieces of text that securely transport information between systems. They are encoded in Base64URL format, making them safe for inclusion in HTTP headers or URLs. Signed (and sometimes encrypted) JWTs allow recipients to verify their integrity, while their self-contained nature enables stateless authentication, eliminating the need for session storage or database/cache lookups.

A JWT consists of three parts—header, payload, and signature—separated by dots. The header contains metadata like the token type and signing algorithm, the payload features claims about the user or system, and the signature ensures the token's integrity. A real-world JWT example is:

```

xxxxx.yyyyy.zzzzz

```

OAuth2 and JWT work together in a system with four key roles: Resource Owner (the entity granting access), Client (the application requesting access), Authorization Server (authenticating the resource owner and issuing access tokens), and Resource Server (hosting protected resources). The Resource Owner grants permission, the Client requests authorization from the Authorization Server, receives an access token (JWT) if approved, and then uses this token to access data from the Resource Server.

Implementing OAuth2 and JWT in a Kotlin and Spring-based backend API can streamline access control. For instance, in a document management system API with endpoints like GET /documents, GET /documents/{id}, and POST /documents, you can restrict access to only authenticated users. By leveraging OAuth2 and JWT, your backend can focus on receiving and validating Bearer Tokens, authenticating their signature, checking expiration, and enforcing scopes/roles, rather than managing complex user login processes or session tracking.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Amazon’s Black Friday ‘Deals’ Were Mostly Decoys – What That Means for Cloud Engineers

1. What was released / announced Groundwork Collaborative’s investigation (see the link above) revealed that nearly 1 in 3 Amazon Black Friday and Cyber Monday deals advertised on the retail site…

  • 33% of Amazon's Black Friday/Cyber Monday deals were not actual savings
  • Nearly 10% of advertised discounts were price increases
  • Impacts budget forecasting, security/compliance, and automation pipelines for cloud engineers

Git Branch Naming Conventions: Patterns and a CI Check

Originally published on DevToolHub . The git branch naming conventions I would use are a lowercase type/short-description pattern, such as fix/empty-password-crash , with an optional ticket number.

  • Git branch names follow a lowercase type/short-description pattern
  • Optional ticket number can be included in branch names
  • CI check validates branch name format for consistency

More from Tuesday 17 November →