Skip to content

[apps/api] feat: allow oauth for regional bots#386

Merged
lilyydu merged 14 commits into
mainfrom
lilyydu/expose-vals
Nov 11, 2025
Merged

[apps/api] feat: allow oauth for regional bots#386
lilyydu merged 14 commits into
mainfrom
lilyydu/expose-vals

Conversation

@lilyydu

@lilyydu lilyydu commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

resolves: #367

  • exposed a new config option called ClientSettings thats passed into our clients from the app layer
  • the tokenUrl specifies the regional token endpoint to use (e.g., europe.token.botframework)

I didn't reuse OauthSettings because
a) its associated w/ the Apps ecosystem vs ClientSettings is concerned w the API layer
b) eventually may diverge with additional params
b) would cause circular dependencies

  • tested with the graph sample, works w/ global and a west-europe regional bot
  • add tests

INSTRUCTIONS FOR SETTING UP
(documenting here for now, should add to docs, partial courtesy to @Benjiiim):

const app = new App({
oauth: {
defaultConnectionName: 'graph',
// This is an example of overriding the token URL for a specific region (e.g., Europe).
// Uncomment this block if needed.
// clientSettings: {
// tokenUrl: "https://europe.token.botframework.com",
// }
},
logger: new ConsoleLogger('@tests/auth', { level: 'debug' })
});

resources:

@Benjiiim

Benjiiim commented Nov 6, 2025

Copy link
Copy Markdown

Loving it 😍 Thanks a lot @lilyydu for your work on this.

I have several comments after going through the changes.

Have you considered using OAuthUrl as the setting's name instead of tokenUrl? I understand the choice for tokenUrl as it is the URL to get the token but the bot service doc talks about OAuth URL in OAuth URL support in Azure AI Bot Service for example so it might be good to be aligned.

Regarding the instructions for setting up:

  • I don't think you should touch the azure.bicep file as resourceGroup().location will get the resource group location automatically + the resource group location doesn't change anything regarding the bot service resource location.
  • You should document the change needed in manifest.json as well. *.botframework.com should be replaced by europe.token.botframework.com (or equivalent for other locations)
  • I will be glad to have a look at the doc when time will come

Regarding the CLI templates:

  • If you choose to add a comment to define the tokenURL in index.ts, you might want to do the same with the validdomain in manifest.json.
  • And you might want to do that for the template applied when running config add atk.oauth to change the reply url in the aad.manifest.json file and the location in azurebot.bicep.
  • Instead of comments everywhere, I'm wondering if env variables won't be better? A discussion with M365 toolkit might be useful in that case to align the templates.
  • An other option would be to rely only on the documentation without touching the templates

Comment thread packages/api/src/clients/client-settings.ts Outdated
Comment thread packages/api/src/clients/bot/sign-in.ts Outdated
Comment thread packages/api/src/clients/bot/sign-in.ts Outdated
Comment thread packages/api/src/clients/client-settings.ts Outdated
Comment thread packages/api/src/clients/client-settings.ts Outdated
Comment thread packages/api/src/clients/client-settings.ts Outdated
Comment thread packages/api/src/clients/index.ts Outdated
Comment thread packages/apps/src/oauth.ts Outdated
Comment thread packages/api/src/clients/client-settings.ts Outdated
Comment thread packages/api/src/clients/api-client-settings.ts
@lilyydu
lilyydu merged commit 13334d6 into main Nov 11, 2025
10 checks passed
@lilyydu
lilyydu deleted the lilyydu/expose-vals branch November 11, 2025 01:07
lilyydu added a commit to microsoft/teams.py that referenced this pull request Nov 14, 2025
## Plan: Add OAuth Support for Regional Bots ✅ COMPLETE

This PR implements OAuth support for regional bots in Python, mirroring
the TypeScript implementation.

### Summary of Changes

#### API Layer (`packages/api`)
- **`ApiClientSettings`**: New dataclass for OAuth endpoint
configuration
  - Defaults to `https://token.botframework.com`
- Supports regional endpoints (e.g.,
`https://europe.token.botframework.com`)
  - Reads from `OAUTH_URL` environment variable
- **`BaseClient`**: Now handles `api_client_settings` for all subclasses
  - Added `api_client_settings` parameter to constructor
  - Calls `merge_api_client_settings` internally
  - All client subclasses inherit this functionality
- **Client updates**: All API clients now inherit settings handling from
BaseClient
- **Endpoint constants**: Added for maintainability
- **Docstrings**: Updated to "Optional API client settings." for
consistency

#### Apps Layer (`packages/apps`)
- **`AppOptions.default_connection_name`**: OAuth connection name
(defaults to "graph")
- **`AppOptions.api_client_settings`**: Top-level field for API client
configuration
- **Removed `OAuthSettings`**: Simplified API by keeping all config in
`AppOptions`
- **Updated references**: Changed from
`options.oauth.default_connection_name` to
`options.default_connection_name`

### Example Usage

```python
from microsoft.teams.api import ApiClientSettings
from microsoft.teams.apps import App

# Configure for Europe region
app = App(
    default_connection_name='graph',
    api_client_settings=ApiClientSettings(
        oauth_url="https://europe.token.botframework.com"
    )
)
```

### Testing
- All 109 API unit tests passing
- Linting passed (ruff)
- Type checking passed (pyright)

### Latest Changes
- ✅ Moved `api_client_settings` handling to `BaseClient` for inheritance
- ✅ All client subclasses now pass settings to BaseClient constructor
- ✅ Removed duplicate `merge_api_client_settings` calls from subclasses
- ✅ Simplified imports by removing unused `merge_api_client_settings`
imports

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>

> in the Python repository, apply similar changes to this Typescript PR
<a href="microsoft/teams.ts#386" rel="noreferrer
noopener" title="microsoft/teams.ts#386"
target="_blank">[apps/api] feat: allow oauth for regional bots by
lilyydu · Pull Request #386 · microsoft/teams.ts</a> <attachment
id="app-preview-card-ps8c1976db18534edbae026f7a1afc8b5e"></attachment>


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: lilyydu <[email protected]>
Co-authored-by: lilydu <[email protected]>
Co-authored-by: Lily Du <[email protected]>
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.

SSO - Support of regional Azure bots

5 participants