I want to get Tenant Id
of my SharePoint online site using SPFX.
Is there any way to get it?
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
SPFx components contain the current tenant id information in the context object as well:
this.context.pageContext.aadInfo.tenantId._guid