11// Msteams plugin module implements token behavior.
22import { isFutureDateTimestampMs } from "openclaw/plugin-sdk/number-runtime" ;
3+ import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime" ;
34import type { MSTeamsConfig } from "../runtime-api.js" ;
45import { loadMSTeamsDelegatedTokens , saveMSTeamsDelegatedTokens } from "./delegated-state.js" ;
56import type { MSTeamsDelegatedTokens } from "./oauth.shared.js" ;
@@ -47,6 +48,20 @@ function resolveAuthType(cfg?: MSTeamsConfig): "secret" | "federated" {
4748 return "secret" ;
4849}
4950
51+ function resolveFederatedString ( configValue : unknown , envValue : unknown ) : string | undefined {
52+ return normalizeOptionalString ( configValue ) ?? normalizeOptionalString ( envValue ) ;
53+ }
54+
55+ function resolveFederatedPath ( configValue ?: string , envValue ?: string ) : string | undefined {
56+ if ( normalizeOptionalString ( configValue ) ) {
57+ return configValue ;
58+ }
59+ if ( normalizeOptionalString ( envValue ) ) {
60+ return envValue ;
61+ }
62+ return undefined ;
63+ }
64+
5065// ── hasConfiguredMSTeamsCredentials ────────────────────────────────────────
5166
5267export function hasConfiguredMSTeamsCredentials ( cfg ?: MSTeamsConfig ) : boolean {
@@ -62,7 +77,9 @@ export function hasConfiguredMSTeamsCredentials(cfg?: MSTeamsConfig): boolean {
6277 ) ;
6378
6479 if ( authType === "federated" ) {
65- const hasCert = Boolean ( cfg ?. certificatePath || process . env . MSTEAMS_CERTIFICATE_PATH ) ;
80+ const hasCert = Boolean (
81+ resolveFederatedPath ( cfg ?. certificatePath , process . env . MSTEAMS_CERTIFICATE_PATH ) ,
82+ ) ;
6683 const hasManagedIdentity =
6784 cfg ?. useManagedIdentity ?? process . env . MSTEAMS_USE_MANAGED_IDENTITY === "true" ;
6885
@@ -95,17 +112,23 @@ export function resolveMSTeamsCredentials(cfg?: MSTeamsConfig): MSTeamsCredentia
95112 }
96113
97114 if ( authType === "federated" ) {
98- const certificatePath =
99- cfg ?. certificatePath || process . env . MSTEAMS_CERTIFICATE_PATH || undefined ;
115+ const certificatePath = resolveFederatedPath (
116+ cfg ?. certificatePath ,
117+ process . env . MSTEAMS_CERTIFICATE_PATH ,
118+ ) ;
100119
101- const certificateThumbprint =
102- cfg ?. certificateThumbprint || process . env . MSTEAMS_CERTIFICATE_THUMBPRINT || undefined ;
120+ const certificateThumbprint = resolveFederatedString (
121+ cfg ?. certificateThumbprint ,
122+ process . env . MSTEAMS_CERTIFICATE_THUMBPRINT ,
123+ ) ;
103124
104125 const useManagedIdentity =
105126 cfg ?. useManagedIdentity ?? process . env . MSTEAMS_USE_MANAGED_IDENTITY === "true" ;
106127
107- const managedIdentityClientId =
108- cfg ?. managedIdentityClientId || process . env . MSTEAMS_MANAGED_IDENTITY_CLIENT_ID || undefined ;
128+ const managedIdentityClientId = resolveFederatedString (
129+ cfg ?. managedIdentityClientId ,
130+ process . env . MSTEAMS_MANAGED_IDENTITY_CLIENT_ID ,
131+ ) ;
109132
110133 // At least one federated mechanism must be configured.
111134 if ( ! certificatePath && ! useManagedIdentity ) {
0 commit comments