/** * Bot Framework OAuth SSO invoke handlers for Microsoft Teams. * * Handles two invoke activities Teams sends when the bot has presented * an `oauthCard` or when the user completes an interactive sign-in: * * 1. `signin/tokenExchange` * The Teams client obtained an exchangeable token from the bot's * AAD app and forwards it to the bot. The bot exchanges that token * with the Bot Framework User Token service, which returns the real * delegated user token (for example, a Microsoft Graph access token * if the OAuth connection is set up for Graph). * * 2. `signin/verifyState` * Fallback for the magic-code flow: the user finishes sign-in in a * browser tab, receives a 6-digit code, and pastes it back into the * chat. The bot then asks the User Token service for the token * corresponding to that code. * * In both cases the bot must reply with an `invokeResponse` (HTTP 200) * immediately or the Teams UI shows "Something went wrong". Callers of * {@link handleSigninTokenExchangeInvoke} and * {@link handleSigninVerifyStateInvoke} are responsible for sending * that ack; these helpers encapsulate token exchange and persistence.
*/
import type { MSTeamsAccessTokenProvider } from "./attachments/types.js"; import type { MSTeamsSsoTokenStore } from "./sso-token-store.js"; import { buildUserAgent } from "./user-agent.js";
export type MSTeamsSsoDeps = {
tokenProvider: MSTeamsAccessTokenProvider;
tokenStore: MSTeamsSsoTokenStore;
connectionName: string; /** Override `fetch` for testing. */
fetchImpl?: MSTeamsSsoFetch; /** Override the User Token service base URL (testing / sovereign clouds). */
userTokenBaseUrl?: string;
};
export type MSTeamsSsoUser = { /** Stable user identifier — AAD object ID when available. */
userId: string; /** Bot Framework channel ID (default: "msteams"). */
channelId?: string;
};
/** * Finish a magic-code sign-in: look up the user token for the state * code via Bot Framework's User Token service, then persist it.
*/
export async function handleSigninVerifyStateInvoke(params: {
value: SigninVerifyStateValue;
user: MSTeamsSsoUser;
deps: MSTeamsSsoDeps;
}): Promise<MSTeamsSsoResult> { const { value, user, deps } = params; if (!user.userId) { return { ok: false, code: "missing_user", message: "no user id on invoke activity" };
} if (!deps.connectionName) { return { ok: false, code: "missing_connection", message: "no OAuth connection name" };
} const state = value.state?.trim(); if (!state) { return { ok: false, code: "missing_state", message: "no state code on invoke" };
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.