getTeamsAppID retrieves the Teams app ID from the app catalog. The app must be published to the organization's app catalog.
(ctx context.Context)
| 282 | // getTeamsAppID retrieves the Teams app ID from the app catalog. |
| 283 | // The app must be published to the organization's app catalog. |
| 284 | func (p *provider) getTeamsAppID(ctx context.Context) (string, error) { |
| 285 | // The externalId in the app catalog is the same as the clientID (Azure AD app ID). |
| 286 | apiURL := fmt.Sprintf("https://graph.microsoft.com/v1.0/appCatalogs/teamsApps?$filter=externalId%%20eq%%20'%s'", p.clientID) |
| 287 | |
| 288 | b, err := p.doGraphRequest(ctx, http.MethodGet, apiURL, nil) |
| 289 | if err != nil { |
| 290 | return "", errors.Wrapf(err, "failed to query app catalog") |
| 291 | } |
| 292 | |
| 293 | var resp struct { |
| 294 | Value []struct { |
| 295 | ID string `json:"id"` |
| 296 | } `json:"value"` |
| 297 | } |
| 298 | if err := json.Unmarshal(b, &resp); err != nil { |
| 299 | return "", errors.Wrapf(err, "failed to unmarshal app catalog response") |
| 300 | } |
| 301 | |
| 302 | if len(resp.Value) == 0 { |
| 303 | return "", errors.Errorf("Teams app with externalId %s not found in app catalog", p.clientID) |
| 304 | } |
| 305 | |
| 306 | return resp.Value[0].ID, nil |
| 307 | } |
| 308 | |
| 309 | // ensureAppInstalledForUser ensures the Teams app is installed for a user. |
| 310 | // Returns the installation ID. |
no test coverage detected