简体   繁体   中英

How to get the tenant id with the azure-devops-extension-api and azure-devops-extension-sdk?

I have a small problem. I'm trying to get the tanant id. I tried to use code below but can only get project id.

import * as SDK from "azure-devops-extension-sdk";
import { CommonServiceIds, IProjectPageService } from "azure-devops-extension-api";
const projectService = await SDK.getService<IProjectPageService>(CommonServiceIds.ProjectPageService);
const project = await projectService.getProject();

Any ideas?

You can find tenant ID in Domain property of below DevOps API call response regarding Identities :

GET https://vssps.dev.azure.com/{organization}/_apis/identities?searchFilter=General&filterValue=<Azure AD username>&queryMembership=None&api-version=7.0

I tried to reproduce the same in my environment via Postman and got below results

To create new Personal access token (PAT), you can find below steps in your DevOps portal:

在此处输入图像描述

I generated one PAT token with full access for my DevOps organization like below:

在此处输入图像描述

When I ran below query including PAT token in Postman, I got tenant ID in response successfully like below:

GET vssps.dev.azure.com/{organization}/_apis/identities?searchFilter=General&filterValue=<Azure AD user UPN>&queryMembership=None&api-version=7.0

Response:

在此处输入图像描述

To confirm that, I checked the same in Azure DevOps portal and got same tenant ID like this:

在此处输入图像描述

Reference: IdentitySelf interface | Microsoft

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM