Skip to content

fix(oauth): derive default scopes per request #190

Open

Description

@baywet

Description

OAuthAccessTokenProvider#get_authorization_token derives a default scope when no scopes were configured, but appends it to the provider's persistent @scopes array. Subsequent requests reuse the first request's scope, even when targeting another allowed host.

Relevant implementation: default-scope derivation and token acquisition.

Reproduction

Use one provider with no explicit scopes and allowed_hosts containing one.example.com and two.example.com. A stub token context is sufficient; no credentials or network requests are needed.

  1. Resume token acquisition for https://one.example.com.
  2. Resume token acquisition for https://two.example.com.
  3. Inspect the scopes supplied to the token context on each request.

Observed: both requests initialize the context with https://one.example.com/.default. This was reproduced using Ruby 3.3 in Docker.

Expected: the first request uses https://one.example.com/.default; the second uses https://two.example.com/.default. Explicitly configured scopes should continue to be used unchanged.

Suggested scope and regression coverage

  • Derive a request-local default scope without turning it into persistent configured scopes or mutating the caller's scopes array.
  • Cover consecutive requests to two allowed HTTPS hosts using the same provider and no explicit scopes.
  • Cover explicit scopes remaining unchanged across requests.
  • Coordinate token-cache behavior with the effective scopes so that fixing cache reuse does not retain a token for a previous request's scope.

Cross-runtime context

The .NET Azure provider, Java Azure provider, and Dart Azure provider derive fallback scopes per request without persisting the derived value as configured scopes. The TypeScript Azure provider currently persists its first derived scope, so this behavior is not consistent across every runtime.

Related work

This issue tracks default-scope selection separately from those changes.

Activity

  1. huong8373tt-beep commented on Oct 24, 2026

    @huong8373tt-beep

    I’d like to work on this issue. I’ll implement request-local default scope derivation, preserve explicitly configured scopes, and add regression coverage for consecutive requests to different allowed hosts. I’ll also verify the token-cache behavior against the effective scope.

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

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions