Skip to content

Document why we perform Webfinger twice #271

Closed

Description

@TheOneRing

For some reason, we perform the Web finger lookup twice.
If that's correct, we should document why we do it.

Unauthenticated

auto *resolveJob = Jobs::ResolveUrlJobFactory(_context->accessManager()).startJob(_context->accountBuilder().serverUrl(), this);

Authenticated

auto *job = Jobs::WebFingerInstanceLookupJobFactory(_context->accessManager(), token).startJob(_context->accountBuilder().serverUrl(), this);

Activity

  1. TheOneRing commented on May 20, 2025

    @TheOneRing
    ContributorAuthor

    @butonic @rhafer do you know why we do that or whether its an artifact from refactoring?

  2. michaelstingl commented on May 26, 2025

    @michaelstingl
    Contributor

    Why OpenCloud Clients Perform WebFinger Twice - Documentation

    The two WebFinger calls are intentional and serve different purposes in the authentication flow. This applies to all OpenCloud clients (Desktop, Mobile, Web).

    Architecture Overview

    sequenceDiagram
        participant User
        participant Client as Client\n(Desktop/Mobile/Web)
        participant LookupServer as Lookup Server\n(OpenCloud)
        participant IdP as IdP\n(OpenCloud)
        participant Instance as User's OpenCloud\nInstance
    
        Note over User,Instance: Phase 1: Server Discovery & Authentication Method Detection
        
        User->>Client: Enter server URL (e.g., opencloud.eu)
        Client->>LookupServer: GET /.well-known/webfinger?resource={serverUrl}\n(Unauthenticated)
        Note right of LookupServer: First WebFinger call:\nCheck if WebFinger auth\nis available
        LookupServer-->>Client: WebFinger response with OIDC issuer link\n(rel="http://openid.net/specs/connect/1.0/issuer")
        Client->>Client: Store authentication server URL
    
        Note over User,Instance: Phase 2: OAuth Authentication
        
        Client->>IdP: GET /.well-known/openid-configuration
        IdP-->>Client: OpenID configuration (auth & token endpoints)
        Client->>User: Open browser for OAuth login
        User->>IdP: Authenticate
        IdP-->>Client: Access token & refresh token
    
        Note over User,Instance: Phase 3: Instance Discovery
        
        Client->>LookupServer: GET /.well-known/webfinger?resource=acct:me@{host}\nAuthorization: Bearer {token}\n(Authenticated)
        Note right of LookupServer: Second WebFinger call:\nDiscover user's\nOpenCloud instance(s)
        LookupServer-->>Client: WebFinger response with instance URLs\n(rel="http://webfinger.opencloud/rel/server-instance")
        Client->>Client: Select first instance from list
        Client->>Instance: Connect to user's OpenCloud instance
    
    Loading

    The Two Calls Explained

    1️⃣ First WebFinger Call (Unauthenticated)

    GET /.well-known/webfinger?resource=https://opencloud.eu
    • Purpose: Discover if server supports WebFinger-based auth and find the IdP
    • Resource: The server URL itself
    • Looking for: rel="http://openid.net/specs/connect/1.0/issuer"
    • Result: URL of the authentication server (IdP)

    2️⃣ Second WebFinger Call (Authenticated)

    GET /.well-known/webfinger?resource=acct:[email protected]
    Authorization: Bearer {token}
    • Purpose: Discover which OpenCloud instance(s) the user has access to
    • Resource: acct:me@{host} (authenticated user identifier)
    • Looking for: rel="http://webfinger.opencloud/rel/server-instance"
    • Result: URL(s) of the user's OpenCloud storage instance(s)

    Why This Design?

    1. Separation of Concerns: Authentication (IdP) can be separate from storage location
    2. Multi-tenancy: Different users can be routed to different storage instances
    3. Single Entry Point: Users only need to know one URL (e.g., opencloud.eu)
    4. Flexibility: All components can run in a single OpenCloud binary or be distributed
    5. Consistent Experience: All clients (Desktop, Mobile, Web) use the same discovery mechanism

    The Lookup Server component in OpenCloud handles both WebFinger requests but with different logic based on authentication state and resource type.

    This is not a refactoring artifact but an intentional design that enables flexible deployment architectures across all client platforms.

  3. kulmann commented on May 27, 2025

    @kulmann
    Member

    This is not a refactoring artifact but an intentional design that enables flexible deployment architectures across all client platforms.

    I can confirm this - at least that's what I understood as well, when we did the implementation back then. See also the service readme: https://github.com/opencloud-eu/opencloud/blob/main/services/webfinger/README.md

  4. TheOneRing commented on May 27, 2025

    @TheOneRing
    ContributorAuthor

    Thanks to you both

  5. Svanvith commented on May 30, 2025

    @Svanvith
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions