Skip to content

Add Support for Limiting M2M Usage via Tenant-Wide Defaults and Client/Organization Overrides #537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

developerkunal
Copy link
Contributor

🔧 Changes

This PR introduces support for configuring token quotas for M2M (client credentials) flows at the tenant, client, and organization levels.

Key Changes:

  • Introduced a unified TokenQuota struct used across tenant, client, and organization resources
  • TenantDefaultTokenQuota now allows configuring default quotas for both clients and organizations
  • Clients and organizations can override the tenant-wide quota by setting their own token_quota field
  • Introduced TokenQuotaClientCredentials, which supports:
    • enforce: whether the quota is strictly enforced or just logged
    • per_day and per_hour limits for issued tokens

Unsetting Quotas

To remove a previously set quota, send a PATCH request with a null value:

# Unset tenant-wide quotas
PATCH /api/v2/tenants/settings
{
  "default_token_quota": null
}

# Unset client-specific quota
PATCH /api/v2/clients/{id}
{
  "token_quota": null
}

# Unset organization-specific quota
PATCH /api/v2/organizations/{id}
{
  "token_quota": null
}

For implementation examples, refer to the Go SDK usage guide:
🔗 https://github.com/auth0/go-auth0/blob/main/EXAMPLES.md#providing-a-custom-user-struct


📚 References


🔬 Testing

  • Unit tests cover all new structs and unmarshal/marshal behaviour
  • Manual tests verified PATCH operations unset values correctly
  • Validated behavior with realistic tenant, client, and org payloads

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@developerkunal developerkunal requested a review from a team as a code owner April 4, 2025 09:12
@codecov-commenter
Copy link

codecov-commenter commented Apr 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.84%. Comparing base (f54fa8c) to head (16d6cfa).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #537      +/-   ##
==========================================
+ Coverage   95.82%   95.84%   +0.01%     
==========================================
  Files          60       60              
  Lines       11639    11690      +51     
==========================================
+ Hits        11153    11204      +51     
  Misses        366      366              
  Partials      120      120              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@developerkunal developerkunal requested a review from Copilot April 6, 2025 17:06
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Copy link
Contributor

@kushalshit27 kushalshit27 left a comment

Choose a reason for hiding this comment

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

It would better to add implementation examples along with unset examples

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.

4 participants