# spring-projects/spring-authorization-server architecture

> Architecture diagram of the GitHub repository spring-projects/spring-authorization-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/spring-projects/spring-authorization-server
- Repository: https://github.com/spring-projects/spring-authorization-server

## Overview

This project is the Spring Authorization Server—a library and server implementation that provides OAuth 2.1 (and related OAuth 2.0) authorization server functionality. It is not a full-stack application per se but rather a server-side framework that leverages Spring Security’s OAuth 2.0 Core, Client, Resource Server, and JOSE modules. It also includes many sample applications (clients, demo authorization servers, SPA clients, etc.) to illustrate how the server and its integrations can be used.

##### Main components
- Authorization Server Core – This is the heart of the system. It comprises components handling OAuth2 endpoints (like /authorize, /token, /consent, etc.), token issuance logic, client registration, and various authentication providers.
- Authentication & Token Processing – Modules that include authentication converters, authentication providers, token generators (access and refresh tokens), and related validation components.
- OIDC and OAuth2 Extensions – Components supporting OpenID Connect (OIDC) such as userinfo, client registration endpoints, and custom id token and claim handling.
- Integration with Spring Security Modules – The project leverages several Spring Security modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) that should be shown as dependencies or collaborating modules.
- Persistence/Repository Layer – Although the core is framework code, there are implementations (in-memory, JDBC, JPA, Redis, etc.) for managing clients, authorizations, and consents.
- Build and Configuration Infrastructure – The buildSrc folder holds custom Gradle plugins and conventions used to configure and standardize the project build. This is also key in the overall architecture.
- Documentation and Samples – The separate docs and samples directories demonstrate various integrations and deployment examples (Backend-for-SPA, default or demo authorization server, demo client, etc.). These samples illustrate different deployment configurations and runtime integrations.

##### Component relationships and interactions
- That the various OAuth2 authentication providers (e.g., Authorization Code Authentication Provider, Refresh Token Provider, Client Credentials Provider, Device Code Provider, etc.) are all plugged into the central authentication context.
- That the different persistence implementations (In-memory, JDBC, JPA, Redis) plug into the repositories responsible for storing client registration and authorization details.
- Build configuration and Gradle plugins (from buildSrc) as supporting layers that define project conventions and documentation deployment (e.g., the Antora docs build).

##### Important architectural patterns
- Extensibility: The design accommodates custom authentication flows (such as device authentication and custom grant types) and an extensible client registration flow, which should be highlighted as optional extension points.

##### Relevant technologies and frameworks
- Gradle (build automation)
- Java 17 (as required)
- Spring Framework (Spring Security, Spring Boot if applicable in samples)
- OAuth 2.1 / OAuth 2.0 standards and OpenID Connect for authentication and authorization
- Integration with external modules like Spring Security OAuth components and JOSE libraries for token security
- Persistence technologies indicated in examples (JPA, JDBC, Redis)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client Request"]

    subgraph "Authorization Flow"
        AS["Authorization Server Core (OAuth2 Endpoints)"]:::core
        AP["Authentication Providers & Converters"]:::auth
        TG["Token Generation & Handling"]:::token
        PR["Persistence/Repository Layer"]:::repo
        OIDC["OIDC and OAuth2 Extensions"]:::oidc
    end

    subgraph "External Modules"
        SS["Spring Security Modules"]:::spring
        BC["Build & Configuration (buildSrc)"]:::build
        DOC["Documentation"]:::docs
        SMP["Samples (Demo Clients & Servers)"]:::sample
    end

    Client -->|"OAuth2Request"| AS
    AS -->|"Authenticate"| AP
    AP -->|"GenerateTokens"| TG
    TG -->|"StoreValidate"| PR
    AS -->|"OIDCExtend"| OIDC

    AS -->|"Uses"| SS
    AP -->|"DependsOn"| SS
    TG -->|"DependsOn"| SS

    AS -->|"ConfiguredBy"| BC

    DOC -->|"Documents"| AS
    SMP -->|"Demonstrates"| AS

    click AS "https://github.com/spring-projects/spring-authorization-server/tree/main/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization"
    click AP "https://github.com/spring-projects/spring-authorization-server/tree/main/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication"
    click TG "https://github.com/spring-projects/spring-authorization-server/tree/main/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/token"
    click OIDC "https://github.com/spring-projects/spring-authorization-server/tree/main/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc"
    click SS "https://github.com/spring-projects/spring-authorization-server/blob/main/dependencies/spring-authorization-server-dependencies.gradle"
    click PR "https://github.com/spring-projects/spring-authorization-server/tree/main/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/client"
    click BC "https://github.com/spring-projects/spring-authorization-server/tree/main/buildSrc"
    click DOC "https://github.com/spring-projects/spring-authorization-server/tree/main/docs"
    click SMP "https://github.com/spring-projects/spring-authorization-server/tree/main/samples"

    classDef core fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef auth fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef token fill:#ffcccb,stroke:#000,stroke-width:2px;
    classDef repo fill:#ffffcc,stroke:#000,stroke-width:2px;
    classDef oidc fill:#dda0dd,stroke:#000,stroke-width:2px;
    classDef spring fill:#f4a460,stroke:#000,stroke-width:2px;
    classDef build fill:#afeeee,stroke:#000,stroke-width:2px;
    classDef docs fill:#e0ffff,stroke:#000,stroke-width:2px;
    classDef sample fill:#ffc0cb,stroke:#000,stroke-width:2px;
```
