AGENT SKILL

添加 Office 365 用户数据源

add-office365-users

通过 `/add-data-source` 并使用 `api-id=shared_office365users` 和操作模式添加 Office 365 Users。用于用户个人资料、经理、直属下属、人员搜索和个人照片。

License 许可
MIT
最近更新
2026-11-06
Stars
★ 36
Forks
12

01 前言 Front Matter

name
add-office365-users
description
Adds Office 365 Users by delegating to `/add-data-source` with `api-id=shared_office365users` and action mode. Use for user profiles, managers, direct reports, people search, and profile photos.
allowed-tools
Read AskUserQuestion Skill

03 SKILL.md 正文

? Shared Instructions: shared-instructions.md — Cross-cutting concerns.

Add Office 365 Users (Wrapper)

This skill is a thin wrapper. Use /add-data-source as the single implementation path.

Delegation contract

Invoke /add-data-source with:

  • api-id: shared_office365users
  • mode: action

Office 365 Users: Method Selection Guide

After the connector is added, import the generated service:

import { Office365UsersService } from '../../generated/services/Office365UsersService'

Use the V2 methods for profiles and reporting relationships:

Scenario Method Result
Current signed-in user MyProfile_V2($select?) One GraphUser_V1
Specific user by ID or UPN UserProfile_V2(id, $select?) One GraphUser_V1
User's manager Manager_V2(id, $select?) One GraphUser_V1
Direct reports DirectReports_V2(id, $select?, $top?) Profiles in result.data.value
Search people SearchUserV2(searchTerm, top?, ...) Search response in result.data.value
Profile photo UserPhotoMetadata(userId), then UserPhoto_V2(id) Metadata, then binary image data

DirectReports_V2 requires the target manager's Microsoft Entra directory ID or user principal name (UPN). For the signed-in user, call MyProfile_V2('id,userPrincipalName'), then pass the returned id or fall back to userPrincipalName. For a known person, pass their directory ID or UPN directly.

Profile and direct-report pattern

Request only the fields the UI needs:

const fields = [
  'id',
  'displayName',
  'jobTitle',
  'department',
  'mail',
  'userPrincipalName',
  'officeLocation',
].join(',')

const myProfile = await Office365UsersService.MyProfile_V2(
  'id,userPrincipalName',
)
if (!myProfile.success) {
  throw new Error(myProfile.error?.message ?? 'Failed to resolve current user')
}

const managerId =
  myProfile.data?.id ?? myProfile.data?.userPrincipalName

if (!managerId) {
  throw new Error('Current user profile did not include an ID or UPN')
}

const result = await Office365UsersService.DirectReports_V2(
  managerId,
  fields,
)

if (!result.success) {
  throw new Error(result.error?.message ?? 'Failed to load direct reports')
}

const people = result.data?.value ?? []

An empty value array is valid and means the user has no direct reports.

Profile photos: binary response and CSP-safe rendering

Call UserPhotoMetadata before downloading the photo. HasPhoto: false is a valid no-photo state; render initials or another accessible fallback.

Image responses are a special runtime contract: the generated UserPhoto_V2 signature may declare IOperationResult<string>, but the Managed Apps SDK decodes an image/* response into a Uint8Array. Do not interpolate that byte array directly into a base64 URL, and do not use a blob: URL—the deployed App Player content security policy may block blob: under img-src.

Convert the bytes to a data: URL:

function bytesToBase64(bytes: Uint8Array) {
  const chunkSize = 0x8000
  let binary = ''

  for (let offset = 0; offset < bytes.length; offset += chunkSize) {
    binary += String.fromCharCode(
      ...bytes.subarray(offset, Math.min(offset + chunkSize, bytes.length)),
    )
  }

  return btoa(binary)
}

function toImageDataUrl(value: unknown, contentType = 'image/jpeg') {
  if (value instanceof Uint8Array) {
    return `data:${contentType};base64,${bytesToBase64(value)}`
  }

  if (value instanceof ArrayBuffer) {
    return `data:${contentType};base64,${bytesToBase64(new Uint8Array(value))}`
  }

  if (typeof value === 'string') {
    if (/^data:image\/[a-z0-9.+-]+;base64,/i.test(value)) {
      return value
    }

    if (/^https?:/i.test(value)) {
      throw new Error(
        'Profile photo returned an HTTP URL instead of binary image data.',
      )
    }

    return `data:${contentType};base64,${value}`
  }

  throw new Error('The profile photo response used an unsupported format.')
}

UserPhoto_V2 has a binary response contract and does not return an external image URL. An HTTP value indicates an unexpected response shape, so the helper rejects it rather than passing a potentially CSP-blocked or authenticated URL to <img src>.

Complete photo flow:

const metadata = await Office365UsersService.UserPhotoMetadata(userId)
if (!metadata.success) {
  throw new Error(metadata.error?.message ?? 'Failed to check profile photo')
}

if (!metadata.data?.HasPhoto) {
  return undefined
}

const photo = await Office365UsersService.UserPhoto_V2(userId)
if (!photo.success) {
  throw new Error(photo.error?.message ?? 'Failed to load profile photo')
}

return photo.data
  ? toImageDataUrl(photo.data, metadata.data.ContentType)
  : undefined

Always fetch photos through the generated connector service. Do not call Microsoft Graph directly and do not assign the authenticated connector runtime URL to <img src>.

04 同仓库更多 Skills

microsoft
microsoft/managed-apps

Microsoft 托管应用状态与附件管理

state

使用 `ms project state` CLI schema 命令和生成的 TypeScript 客户端,存储与查询 Microsoft 托管应用的内置状态和文件附件。首先,在用户登录 CLI 后运行 `ms feature status --name state --json`;如果 `feature.enabled` 不为 `true`,则推荐替代的连接器或数据源。

软件开发工程师低代码应用开发
★ 36
microsoft
microsoft/managed-apps

Microsoft 应用共享与访问控制

share

通过 `ms app share` / `ms app unshare` 与用户共享(或取消共享)Microsoft 应用。在需要更新应用访问控制时使用。

IT 管理员身份与访问管理
★ 36
microsoft
microsoft/managed-apps

Microsoft App 共享链接管理

share-link

通过 `ms app share link create`、`ms app share link list` 和 `ms app share link revoke` 管理 Microsoft App 的租户级共享链接。适用于希望通过 URL(而非指定主体)来分发应用访问权限的场景。

软件开发工程师身份与访问管理
★ 36
microsoft
microsoft/managed-apps

Microsoft App 浏览器预览

play

通过 `ms app play` 在浏览器中打开 Microsoft App。适用于打开已部署的线上版本或云端托管的预览版本(主分支或特定提交 SHA),而无需启动本地开发服务器。

软件开发工程师开发环境与工具链管理
★ 36
microsoft
microsoft/managed-apps

可用连接器列表查询

list-connectors

列出当前活动环境中可用的连接器——包括每个连接器是被组织策略允许还是阻止——以及已接入 Microsoft App 的连接绑定数据源。适用于在添加数据源之前发现可用的连接器及其操作。

软件开发工程师应用连接器集成
★ 36
microsoft
microsoft/managed-apps

Microsoft 应用列表查询

list-apps

通过 `ms app list --json` 以及可选的 `ms app show --json` 发现活动环境中的受管理应用。在列出或定位应用时使用。

软件开发工程师Microsoft 应用生命周期管理
★ 36