-
Notifications
You must be signed in to change notification settings - Fork 24
fix: Apply default values to custom AuthConfiguration in CloudAdapter #579
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
Conversation
|
@microsoft-github-policy-service agree |
|
Hi @Namielusi, thank you very much for looking at this. When using a custom authConfig you must configure the const authConfig: AuthConfiguration = {
clientId: '',
clientSecret: '',
tenantId: '',
}
As the issuers are built on top of the Keep in mind that
or maybe I'm missing something from you use case... |
|
Hi @rido-min! In my use case, I use custom names for environment variables, hence I can't make use of In my code, the initialisation of const adapter = new CloudAdapter({
clientId: config.microsoftClientId,
clientSecret: config.microsoftClientSecret,
// Reference: https://github.com/microsoft/Agents-for-js/blob/ecd5464d28e3e20e2cd5664c5dc55d16003fa9bb/packages/agents-hosting/src/auth/authConfiguration.ts#L88C57-L88C90
authority: 'https://login.microsoftonline.com',
// Reference: https://github.com/microsoft/Agents-for-js/blob/ecd5464d28e3e20e2cd5664c5dc55d16003fa9bb/packages/agents-hosting/src/auth/authConfiguration.ts#L101-L105
issuers: [
'https://api.botframework.com',
`https://sts.windows.net/${config.microsoftTenantId}/`,
`https://login.microsoftonline.com/${config.microsoftTenantId}/v2.0`,
],
});Prior to creating this PR I've spent some time debugging the Agents-for-js/packages/agents-hosting/src/auth/msalTokenProvider.ts Lines 162 to 176 in ecd5464
What I've found is that you have to explicitly provide value for With this PR, my code can be simplified to: const adapter = new CloudAdapter({
clientId: config.microsoftClientId,
clientSecret: config.microsoftClientSecret,
});Alternative approach would be to fix the interface ( |
|
I think this bug was introduced in #467, previously, it was working fine without providing In any case, the main priority for me is to fix the What do you think? |
|
oh... I see now. Yes, you are right, we should rethink how In the meantime, I want to make sure you are not blocked and can use your custom
|
|
Hi @Namielusi, thanks for your contribution! We used your PR as a base for the solution that was integrated into PR #573 (commit). Since the fix is now included there, feel free to close this PR if you agree. Thanks! /c @MattB-msft |
Description
This PR fixes an issue where the
authorityfield is not properly populated when a customAuthConfigurationis provided toCloudAdapter, despite this field being marked as optional in the TypeScript interface.Problem
When creating a
CloudAdapterwith a custom authentication configuration, the optionalauthorityfield was not receiving its default value. This caused runtime errors inMsalTokenProvidermethods that expectauthorityto be defined, even though TypeScript types suggest it's optional.Error Example
When adapter tries to acquire token, it fails with:
Solution
Implemented a new helper function
applyAuthConfigDefaults()that automatically applies default values to anyAuthConfigurationobject, ensuring consistency between custom configs and those loaded from environment variables.The
CloudAdapterconstructor now uses this helper to apply defaults when a customauthConfigis provided, ensuring thatauthorityand other optional fields receive their appropriate default values. This maintains backward compatibility while preventing runtime errors.