Obtaining an Authentication Token to Access SharePoint Term Store APIs
(Part Two of a Three-Part Term Store Series)
In our last blog, Getting Started with SharePoint Term Store, we answered the questions:
- What is the SharePoint term store?
- How does the term store hierarchy work?
- How do we set up terms on the SharePoint term store?
- How does Bamboo’s Knowledge Base integrate with the term store?
This blog will dive deeper and explore:
- How do I create an Azure AD application?
- How do I integrate an app into my SPFx solution?
- And a hack to extract an already existing token from within the SharePoint site!
Microsoft recommends using a specific flow to obtain access to any resource. This flow starts by creating an application from the Azure portal and then granting it access to the resource.
How do I create an Azure AD application?
- Log onto the Azure AD portal, http://aad.portal.azure.com/
- Head over to App registrations from the navigation pane.
- Click on New registration from the top of the panel.
- Register a single page application (SPA) with a redirect URI pointing to the site URL where the webpart is intended to be installed.
- On successful creation of the app registration, head over to API Permission from the navigation pane on the left.
- Then select Add a permission as show in the screenshot below.
- Select SharePoint API and then select Delegated permissions, and add the following permissions to grant to the app:
- Read.All
- ReadWrite.All
How do I integrate the app into my SPFx solution?
- Head over to your SPFx solution/ webpart and the install it. Add a reference to ‘msal-browser’. The snippets are as follows:
- npm i @azure/msal-browser
- import * as msal from “@azure/msal-browser”;
- Use the following snippets to obtain OAuth token to access the SharePoint Term store:
That’s it! You should now have an authentication token to access SharePoint Term Store APIs.
HACK! – An alternative way
The following approach can also be used to extract an already existing token from within the SharePoint site.
Furthermore, when any SharePoint site page loads, it makes requests to obtain various OAuth tokens and then stores them on the browser’s session storage. An access token pertaining to the term store access can be identified if the scopes key consists of the keyword ‘TermStore’.
However, the following code illustrates accessing the term store’s token from the browser’s session storage.
Hopefully, you’re empowered to begin using the term store! In conclusion, if you are interested in learning more about the integration of the SharePoint term store, read the first article in this 3-part series Getting Started with SharePoint Term Store (Part One of a Three Part Term Store Series) watch for the upcoming third blog in this series: SharePoint Term Store APIs. And for a refresher on the basics, check out our first blog from the series: Getting Started with SharePoint Term Store.
Finally, did you know that Bamboo Solutions offers M365 products as well as services? Find out more at our website or contact us to discuss how we can help you make the most of SharePoint, the term store, and M365!
SharePoint Online
The cloud parts are functional components that extend your SharePoint Online environment in Microsoft 365.
Supports Classic and Modern sites for SharePoint Online/Microsoft 365
Small Business Pricing and Discounts
SharePoint
Top SharePoint Online Products
Experience greater power and savings by bundling our SharePoint apps and cloud parts.
On-Premises Only
These web parts extend SharePoint beyond its out-of-the-box capabilities by tailoring it to your requirements with Bamboo Solution’s growing portfolio of SharePoint Web Parts.
SharePoint 2016, 2019, 2022 – Classic Pages Only
SharePoint
Top On-Premises Only Products
Experience greater power and savings by bundling our SharePoint apps and web parts.
Our team of Microsoft 365 Technology Consultants helps you get the most out of your Microsoft technology, we have the best Microsoft 365 talent to streamline your organization.
Consulting to Streamline Your Department
M365 Plus
Managed Services
Microsoft 365
Consulting to Streamline Your Department
Our Consultants Have What You Need
Federal Contractors
Microsoft 365
Our Consultants Have What You Need