1

I want to get Tenant Id of my SharePoint online site using SPFX.

Is there any way to get it?

2 Answers 2

1

SO, Finally i got the solution for that. For that you have to call API and i.e. https://your_site.sharepoint.com/_vti_bin/client.svc.

I am providing the function to get TenantID.

static getTenant() {

const request = new Request('https://{your_site}.sharepoint.com/_vti_bin/client.svc', {
  method: 'GET',
  headers: new Headers({
    'Authorization': 'bearer'
  })
});
return fetch(request).then(response => {
  var data = response.headers.get('WWW-Authenticate').split(',');
  return data;
  }).catch(error => {
  return error;
});
}

You will get the Bearer realm component and that's your tenant ID.

or you can get it by other way.

Follow the article to get TenantID i.e

http://www.anujchaudhary.com/2016/01/azure-active-directory-get-tenant-id.html

1

SPFx components contain the current tenant id information in the context object as well:

this.context.pageContext.aadInfo.tenantId._guid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.