# twocanoes/xcreds architecture

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

- Interactive diagram: https://gitdiagram.com/twocanoes/xcreds
- Repository: https://github.com/twocanoes/xcreds

## Overview

##### Project type and purpose
- XCreds is a macOS-specific, full-stack authentication/synchronization solution. It replaces the native login window with a custom Security Agent (“XCreds Login”) to authenticate against a cloud OIDC provider (Azure/Google), then syncs that cloud password back down into the local macOS account and user keychain. A companion app (“XCreds App”) runs in user space after log in to refresh tokens and re-sync passwords. Additional components include a Safari-style AutoFill extension and a low-level “tap” driver for token sessions.

##### File structure
- Top-level targets and directories
- XCredsLoginPlugIn – the Security Agent plugin run by macOS at login
- XCreds Login Overlay – a helper that provides a custom overlay UI in the login window
- XCreds – the user-space macOS status-menu app and login-item that performs ongoing sync
- XCreds AutoFill Extension – a Credential Provider extension for iOS/macOS autofill
- tap – a system extension/driver implementing TokenSession and hardware interfaces
- authrights, auth_mech_fixup, scripts – helper CLI tools for automation, testing, and entitlement adjustments
- Shared – code and utilities common to multiple components (AuthRightsHelper, Tokens, ManagedPreferences)
- build_resources, scripts, build.sh – packaging, build-and-release infrastructure

##### README for additional insights
- The README describes the two high-level runtime components (Login agent + App), their use of OIDC, token storage in the login keychain, syncing of local password, and requirement to support MFA.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Pre-login stage
    subgraph "Pre-login"
        macOS["macOS Authentication Subsystem"]:::os
        XCredsLoginPlugIn["XCredsLoginPlugIn\n(SecurityAgent Plugin)"]:::core
        XCredsLoginOverlay["XCreds Login Overlay\n(Custom UI)"]:::ui
        LoginKeychain(("Login Keychain")):::core
        DirServices["Directory Services API\n& TCSTaskHelper"]:::os
        OIDCProvider["OIDC Provider\n(Azure/Google)"]:::external
    end

    macOS --> XCredsLoginPlugIn
    XCredsLoginPlugIn --> XCredsLoginOverlay
    XCredsLoginOverlay -->|"WebView OIDC"| OIDCProvider
    OIDCProvider -->|"Tokens"| XCredsLoginPlugIn
    XCredsLoginPlugIn -->|"Store Tokens"| LoginKeychain
    XCredsLoginPlugIn -->|"Update Local Password"| DirServices

    %% Post-login stage
    subgraph "Post-login"
        XCredsApp["XCreds App\n(User-space Sync)"]:::core
        UserKeychain(("User Keychain")):::core
        XCredsAutoFillExt["XCreds AutoFill Extension\n(Credential Provider)"]:::ui
        Safari["Safari/System"]:::external
    end

    LoginKeychain --> XCredsApp
    XCredsApp -->|"Read/Refresh Tokens"| LoginKeychain
    XCredsApp -->|"Update Tokens & Password"| UserKeychain
    XCredsApp -->|"Sync Password"| DirServices
    XCredsApp --> XCredsAutoFillExt
    XCredsAutoFillExt -->|"Supply Credentials"| Safari
    XCredsAutoFillExt --> UserKeychain

    %% Shared Core Libraries
    subgraph "Shared Core Library"
        Shared["Shared\n(OIDC, TokenManager, Preferences)"]:::core
    end

    Shared --> XCredsLoginPlugIn
    Shared --> XCredsApp
    Shared --> XCredsAutoFillExt
    Shared --> tap

    %% System Extension / Driver
    subgraph "tap System Extension / Driver" 
        tap["tap\n(TokenSession Driver)"]:::os
    end

    tap --> Shared

    %% Packaging & CLI Tools
    subgraph "Packaging & Build Tools"
        authrights["authrights CLI"]:::core
        auth_mech_fixup["auth_mech_fixup CLI"]:::core
        build_sh["build.sh"]:::core
        build_resources["build_resources"]:::core
    end

    build_sh --> build_resources
    build_sh --> XCredsLoginPlugIn
    build_sh --> XCredsApp
    build_sh --> XCredsAutoFillExt
    build_sh --> tap

    %% Click Events
    click XCredsLoginPlugIn "https://github.com/twocanoes/xcreds/tree/main/XCredsLoginPlugIn/"
    click XCredsLoginOverlay "https://github.com/twocanoes/xcreds/tree/main/XCreds Login Overlay/"
    click XCredsApp "https://github.com/twocanoes/xcreds/tree/main/XCreds/"
    click XCredsAutoFillExt "https://github.com/twocanoes/xcreds/tree/main/XCreds AutoFill Extension/"
    click tap "https://github.com/twocanoes/xcreds/tree/main/tap/"
    click Shared "https://github.com/twocanoes/xcreds/tree/main/Shared/"
    click authrights "https://github.com/twocanoes/xcreds/tree/main/authrights/"
    click auth_mech_fixup "https://github.com/twocanoes/xcreds/tree/main/auth_mech_fixup/"
    click build_sh "https://github.com/twocanoes/xcreds/blob/main/build.sh"
    click build_resources "https://github.com/twocanoes/xcreds/tree/main/build_resources/"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000
    classDef core fill:#90EE90,stroke:#000
    classDef os fill:#FFA500,stroke:#000
    classDef external fill:#D3D3D3,stroke:#000
```
