%% NOTE: The following diagram represents the request flow when user
%%       requests authentication from the server.

sequenceDiagram
    
    participant Browser
    

    participant API as NestJS API Server
    participant Keycloak
    participant OAuthProvider as OAuth Provider

    %% trpc.viewer
    autonumber

    Note left of Browser: Browser has no session
    Browser->>API: Get OAuth URL
    API-->>Browser: OAuth URL
    
    
    Browser->>+OAuthProvider: GET /url
    OAuthProvider-->>Browser: Login Website

    Browser->>OAuthProvider: POST /login
    OAuthProvider-->>-Browser: Redirect /callback

    Browser->>API: GET /callback
    API->>Keycloak: GET Access Token using Code
    Keycloak-->>API: Access Token

    API-->>Browser: Redirect Origin, Set Cookie

    Note left of Browser: Browser has a valid Cookie


%% Solid line with arrow: ->>
%% Dotted line with arrow: -->>
%% Solid line without arrow: ->
%% Dotted line without arrow: -->
%% Line with a cross: -x
%% Dotted line with a cross: --x
%% Asynchronous message: -) (Solid), --) (Dotted)