# umbraco/umbraco.authorizedservices architecture

> Architecture diagram of the GitHub repository umbraco/umbraco.authorizedservices, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/umbraco/umbraco.authorizedservices
- Repository: https://github.com/umbraco/umbraco.authorizedservices

## Overview

Key Components to Include:

##### Core System Components
- Backoffice UI Layer (Settings Section Tree)
- Authorization Service Layer
- Storage Layer
- API Integration Layer
- Configuration Management

##### External Integration Points
- Third-party OAuth Services
- API Key Services
- Umbraco CMS Core

##### Top Level (User Interface)
- [Umbraco Backoffice UI]
- Settings Section
- Authorized Services Tree

##### Middle Layer (Service Management)
- [Authorization Services]
- AuthorizedServiceAuthorizer
- AuthorizationUrlBuilder
- TokenFactory
- ServiceResponseMetadataParser

##### Storage Layer
- [Storage Services]
- DatabaseKeyStorage
- DatabaseOAuth1TokenStorage
- DatabaseOAuth2TokenStorage
- SecretEncryptor

##### Integration Layer
- [External Service Integration]
- AuthorizedServiceCaller
- AuthorizationRequestSender
- AuthorizedRequestBuilder
- API endpoints and connections

##### Configuration Layer
- [Configuration Management]
- Service Settings
- Authentication Methods
- API Configurations
- Configuration flow

Important Flows to Highlight:

##### OAuth2 Authorization Flow
- Intermediate steps (authorization, token exchange, storage)
- Use different line styles for different types of requests

##### OAuth1 Authorization Flow
- Similar to OAuth2 but with OAuth1-specific components
- Request token and access token exchange process

##### API Key Flow
- Simpler direct flow for API key authentication
- Encryption and storage steps

Design Guidelines:

##### Component Relationships
- Clear dependencies between components
- Interface implementations

##### Labels and Documentation
- Clear labels for all components
- Brief descriptions for key processes
- Interface names where relevant

##### Security Flow
- Encryption points
- Token storage security
- Secure communication channels

##### Error Handling
- Error flow paths
- Retry mechanisms
- Fallback processes

- Clear component representation
- Export to common formats
- Easy updates and modifications

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef ui fill:#a8d1f0,stroke:#2c89c4
    classDef service fill:#90EE90,stroke:#006400
    classDef storage fill:#FFE4B5,stroke:#DAA520
    classDef integration fill:#DDA0DD,stroke:#8B008B
    classDef config fill:#D3D3D3,stroke:#696969
    classDef security fill:#FFB6C1,stroke:#FF69B7

    %% UI Layer
    subgraph BackofficeUI
        UI[Umbraco Backoffice UI]:::ui
        Settings[Settings Section]:::ui
        Tree[Authorized Services Tree]:::ui
    end

    %% Authorization Service Layer
    subgraph AuthServices
        Authorizer[AuthorizedServiceAuthorizer]:::service
        UrlBuilder[AuthorizationUrlBuilder]:::service
        TokenFact[TokenFactory]:::service
        MetaParser[ServiceResponseMetadataParser]:::service
    end

    %% Storage Layer
    subgraph StorageLayer
        KeyStorage[DatabaseKeyStorage]:::storage
        OAuth1Storage[DatabaseOAuth1TokenStorage]:::storage
        OAuth2Storage[DatabaseOAuth2TokenStorage]:::storage
        SecretEnc[SecretEncryptor]:::security
    end

    %% Integration Layer
    subgraph IntegrationLayer
        ServiceCaller[AuthorizedServiceCaller]:::integration
        RequestSender[AuthorizationRequestSender]:::integration
        RequestBuilder[AuthorizedRequestBuilder]:::integration
    end

    %% Configuration Layer
    subgraph ConfigLayer
        ServiceSettings[Service Settings]:::config
        AuthMethods[Authentication Methods]:::config
        APIConfig[API Configurations]:::config
    end

    %% External Systems
    OAuth[OAuth Providers]
    APIKeys[API Key Services]
    UmbracoCMS[Umbraco CMS Core]

    %% Relationships
    UI --> Settings
    Settings --> Tree
    Tree --> Authorizer
    Authorizer --> UrlBuilder
    UrlBuilder --> RequestSender
    RequestSender --> TokenFact
    TokenFact --> |Store Tokens| StorageLayer
    ServiceCaller --> RequestBuilder
    RequestBuilder --> |Use Stored Tokens| StorageLayer
    ConfigLayer --> AuthServices
    SecretEnc --> StorageLayer
    RequestSender --> OAuth
    ServiceCaller --> APIKeys
    UmbracoCMS --> UI

    %% Click events
    click Tree "https://github.com/umbraco/Umbraco.AuthorizedServices/tree/main/src/Umbraco.AuthorizedServices/Client/src/tree"
    click UI "https://github.com/umbraco/Umbraco.AuthorizedServices/tree/main/src/Umbraco.AuthorizedServices/Client/src/workspace"
    click Authorizer "https://github.com/umbraco/Umbraco.AuthorizedServices/blob/main/src/Umbraco.AuthorizedServices/Services/Implement/AuthorizedServiceAuthorizer.cs"
    click UrlBuilder "https://github.com/umbraco/Umbraco.AuthorizedServices/blob/main/src/Umbraco.AuthorizedServices/Services/Implement/AuthorizationUrlBuilder.cs"
    click TokenFact "https://github.com/umbraco/Umbraco.AuthorizedServices/blob/main/src/Umbraco.AuthorizedServices/Services/Implement/TokenFactory.cs"
    click StorageLayer "https://github.com/umbraco/Umbraco.AuthorizedServices/tree/main/src/Umbraco.AuthorizedServices/Persistence"
    click KeyStorage "https://github.com/umbraco/Umbraco.AuthorizedServices/blob/main/src/Umbraco.AuthorizedServices/Services/Implement/DatabaseKeyStorage.cs"
    click OAuth1Storage "https://github.com/umbraco/Umbraco.AuthorizedServices/blob/main/src/Umbraco.AuthorizedServices/Services/Implement/DatabaseOAuth1TokenStorage.cs"
    click OAuth2Storage "https://github.com/umbraco/Umbraco.AuthorizedServices/blob/main/src/Umbraco.AuthorizedServices/Services/Implement/DatabaseOAuth2TokenStorage.cs"
    click ServiceCaller "https://github.com/umbraco/Umbraco.AuthorizedServices/blob/main/src/Umbraco.AuthorizedServices/Services/Implement/AuthorizedServiceCaller.cs"
    click RequestSender "https://github.com/umbraco/Umbraco.AuthorizedServices/blob/main/src/Umbraco.AuthorizedServices/Services/Implement/AuthorizationRequestSender.cs"
    click IntegrationLayer "https://github.com/umbraco/Umbraco.AuthorizedServices/tree/main/src/Umbraco.AuthorizedServices/Api/Management/Controllers"
    click ServiceSettings "https://github.com/umbraco/Umbraco.AuthorizedServices/blob/main/src/Umbraco.AuthorizedServices/Configuration/AuthorizedServiceSettings.cs"
    click APIConfig "https://github.com/umbraco/Umbraco.AuthorizedServices/blob/main/src/Umbraco.AuthorizedServices/Configuration/ConfigureServiceDetail.cs"
    click SecretEnc "https://github.com/umbraco/Umbraco.AuthorizedServices/blob/main/src/Umbraco.AuthorizedServices/Services/Implement/AesSecretEncryptor.cs"

    %% Legend
    subgraph Legend
        UI_Legend[UI Components]:::ui
        Service_Legend[Service Components]:::service
        Storage_Legend[Storage Components]:::storage
        Integration_Legend[Integration Components]:::integration
        Config_Legend[Configuration Components]:::config
        Security_Legend[Security Components]:::security
    end
```
