Skip to content

✨ Add URI-based repository methods to support federated architecture#75

Merged
CalebGerman merged 19 commits intomainfrom
cg/get-repository-by-uri
Jan 28, 2026
Merged

✨ Add URI-based repository methods to support federated architecture#75
CalebGerman merged 19 commits intomainfrom
cg/get-repository-by-uri

Conversation

@CalebGerman
Copy link
Collaborator

@CalebGerman CalebGerman commented Jan 22, 2026

Pull Request Summary: URI-Based Repository Methods & Federated Architecture Support

Overview

This PR adds URI-based repository methods and secure HTTP 302 redirect handling to support Bentley's federated API architecture. Client code can now seamlessly work with distributed repository services across different backend systems.

🎯 Key Features

1. URI-Based Repository Methods

Three new methods accept capability URIs directly from repository metadata:

  • getRepositoryResourcesByUri() - Retrieve multiple resources with OData support
  • getRepositoryResourceByUri() - Retrieve single resource
  • getResourceGraphicsByUri() - Retrieve graphics metadata
const repo = await client.getRepository(token, iTwinId, repositoryId);
const uri = repo.data?.repository.capabilities?.resources?.uri;

// Use URI directly - handles redirects automatically
const resources = await client.getRepositoryResourcesByUri(token, uri);

2. HTTP 302 Redirect Support

Repository resource endpoints now automatically follow redirects:

  • getRepositoryResource()
  • getRepositoryResources()
  • getResourceGraphics()
  • ✅ All URI-based methods

3. Secure Redirect Handling

Security features ensure safe credential forwarding within Bentley's trust boundary:

  • Domain Whitelisting - Only api.bentley.com and subdomains allowed
  • HTTPS Enforcement - Prevents protocol downgrade attacks
  • Authentication Forwarding - Original headers forwarded through redirect chain
  • Loop Prevention - Maximum 5 redirects per request
// ✅ Valid redirects
https://api.bentley.com → https://dev-api.bentley.com/uds

// ❌ Blocked redirects
https://api.bentley.com → https://evil.com (untrusted domain)
https://api.bentley.com → http://api.bentley.com (protocol downgrade)

🏗️ Architecture

Federated routing enables specialized services for different resource types:

Client → api.bentley.com → (302) → dev-api.bentley.com/uds → Response

All Bentley subdomains share the same trust boundary with consistent token validation.

📝 API Changes

Added abstract methods to BaseITwinsApiClient and fixed updateRepository signature to use proper Partial type.

🔒 Security

Implements OWASP best practices:

  • SSRF prevention via domain whitelist
  • Protocol downgrade protection
  • Redirect loop protection
  • 27 comprehensive security test cases

🚀 Usage

// URI-based approach (recommended)
const repo = await client.getRepository(token, iTwinId, repositoryId);
const uri = repo.data?.repository.capabilities?.resources?.uri;
const resources = await client.getRepositoryResourcesByUri(token, uri,
  { search: "Building", top: 10 }, "representation");

// ID-based approach (also supports redirects)
const resource = await client.getRepositoryResource(
  token, iTwinId, repositoryId, resourceId, "representation");

📊 Benefits

  • Developers: Simplified API, transparent routing, type safety
  • Operations: Service scalability, geographic distribution, zero-downtime migration
  • Security: Defense in depth, credential protection, OWASP compliance

✅ Summary

  • Three URI-based methods for federated architecture
  • Redirect support for repository resource endpoints
  • Comprehensive security validation (SSRF, protocol downgrade, loop prevention)
  • No breaking changes

Type: ✨ Feature | Breaking Changes: None | Security: Enhanced

- Added `getRepositoryResourcesByUri` and `getRepositoryResourceByUri` methods to support federated repository architecture.
- Updated existing methods to deprecate `getRepositoryResource` and `getRepositoryResources`, providing migration examples in documentation.
- Enhanced `RepositoryCapabilities` interface to include graphics capabilities.
- Implemented tests for new URI-based methods, including resource retrieval and graphics metadata access.
- Added backward compatibility tests to ensure deprecated methods still function correctly.
- Introduced migration pattern tests to demonstrate transitioning from deprecated to new methods.
@CalebGerman CalebGerman marked this pull request as ready for review January 26, 2026 21:58
Copy link
Collaborator

@davidbryant222 davidbryant222 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had one comment. Other than that it looks good.

@CalebGerman CalebGerman enabled auto-merge (squash) January 28, 2026 21:50
@CalebGerman CalebGerman merged commit 5bff454 into main Jan 28, 2026
2 checks passed
@CalebGerman CalebGerman deleted the cg/get-repository-by-uri branch January 28, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants