02 03 Demo Create an API endpoint

Microsoft 365 Developer · Beginner ·📰 AI News & Updates ·4y ago

Key Takeaways

The video demonstrates creating an API endpoint for a meetings app using Azure AD MSAL Node package, Microsoft Graph, and JSON database, with a focus on authentication, authorization, and data storage. The API endpoint is designed to retrieve meeting details and stand-up topics from a JSON database.

Full Transcript

now the meeting app is going to need to primarily run client-side code within tabs in the microsoft teams client however we do have some requirements for server-side logic so for example we have two we are going to need to obtain an access token using the azure id uh support for the oauth 2 on behalf of flow and we're going to use this to take the sso token that microsoft teams gives us and we're going to exchange it with azure a t to obtain the token that we can use to call the microsoft graph endpoint to get information about the microsoft teams meeting and then we're also going to use it because we're going to need to read and write details about our stand-up meetings that we have to some sort of a database in a persistent store when our attendees submit topics we want to be able to save those for later use so the meeting can collect additional information from meeting attendees so again we're going to do this about use topics to discuss and present during the meeting in a production app you're probably going to want to store these in a secure persistent store however in this demo that i'm doing here i'm going to keep this very simple and store the data for the stand-up meeting topics in just local json files on my development machine just to simplify this and focus on the team's aspect of our app so to satisfy these requirements i may need to create an api for our application so what i'm going to do is i'm going to install a few things so i'm going to go ahead and open up the console in our app and i'm going to paste in this string here now what this is going to do is i'm going to install the json web web tokens package the jwk s rsa package the azure adm cell node package and the node persist package i'm going to go ahead and install all of these so while these are installing let me explain what these are going to be used for the json web token is going to be used for us to work with jwt file jwt tokens that we receive back these security tokens the jwks rsa is going to be used to um parse out the security or the certificates that azure ad uses to sign tokens so that we can use that to verify the digital signature the azure id msl node package that's what we're going to be using to actually make our request authenticate with azure id and node persist that's used for our local in-memory uh database that we're going to have for our our meeting app project i'm also going to solve some developer dependencies uh like the graph types the node persist type declarations type decorations for the json web token package and for the node persist package as well so it's going to make my my developer experience a little bit easier okay so now that's done we look at our package.json and we can see we've got all those packages we installed there's msl node there's jwcass jw ks rsa the json web token as well as node persist then we have some developer dependencies that went with it as well so what i'm going to do is come over here to our server folder in our project i'm going to create a new folder here called api and inside of this api folder i'm going to create a new file called the auth off utils.ts now i'm going to go and just paste some code in here and explain what this does briefly so what this code does is i've got a method here called get signing keys and what that does is it's going to use the jwks package that we just created or that we just installed to go request all of the keys that are used by azure id this is an anonymous request and we're going to use that to match a specific key that we get back in the header of the request of the jwt token that we get back from microsoft teams and from microsoft graph and azure id this way we're going to be able to use this to verify that this token we got back is actually coming from azure ad and it was signed by azure id we also have a method that we're going to that we're going to expose here called validate token and it's just going to use that method we just defined above to effectively say go look at the token we got call the verify method and we're gonna pass in the token and or that we're gonna use the library called jwt called the verify method pass in the token we got back from microsoft teams or from azure id or they're both coming from azure id get using the signing keys and then passing in any validation options like making sure that it's intended for our app now the next thing i'm going to do is i'm going to add in an api router for our project so i'm going to do that by coming over here and creating a new api file a new file in our api folder and we're going to call this our standup agenda router dot ts and in here i'm going to paste this in so we have our stand up agenda router that we've defined now with the api router created i'm going to need to add three endpoints to it all right so our three endpoints is going to be we have a couple different things we're going to do so we have let's go ahead and add these in all right so let's see what these are so our first endpoint that we've added here is called is the meeting details and it's going to accept a get request and it's going the second part of the path is going to be the id of our meeting it's going to implement the on behalf of flow as well um so what this does is when i request the meeting details it's going to pass in the token so i'm going to validate the token and then i'm going to get in on behalf of flow token and so what that does is that is using um scroll down a little bit farther what that's doing is it's going to be issuing a request using the azure ad msal node package that we just that we installed and it's going to issue requests to create a confidential client application using our app id and the secret that we used for our our tenant so those are all the environment variables that we specified it's requesting it's passing in uh the request for the token so it's going to it's going to acquire a token on behalf of use the token that we have so it's passing in the token there's the assertion we're doing and the scopes these are the permissions that we're requesting so it's then going to use the token that we got from microsoft teams to pass that in now we've done once once we've gotten our token actually restate that we're going to use that token we just got that you can see right here and we're going to use that to issue a request to microsoft graph so remember from our slides we're going to issue request for the chat endpoint after we've stripped off all of the leading zero hash and the trailing zeros from the meeting id that was passed in on the url i'm going to get an instance of that chat and then i'm going to use that same chat value to get the to issue a request for online meetings and match it to the specific url of our meetings join url what that's then going to do is that is going we're going to grab the first meeting that was returned which should be the only meeting that was returned and that's going to give us back the actual details of the actual meeting so there's our meeting there's the data we're going to get the first one that came back and we're going to return that back to the caller next we're going to add another endpoint for stand-up topics this is going to read the stand-up topics for the current meeting from our little json database and return that back to the caller and then the third method that we're going to implement is going to write those it's going to accept the post and it's going to write the stand-up topics for the current meeting to our json database all right so we're just going to format the code so everything looks good and we are in good shape now the next thing i need to do now to create our api router is i need to register it with the server when the server spins up so i'm going to go over here to the server.ts file and what i need to do is i need to import two statements at the top the first one is going to be our stand-up router and the other one is going to be the node persist database now the next thing i need to do is let's go let's scroll down to the statement where we have a use statement right here so there's our use statement and right before the statement for express which is our web server i'm going to add my router as a ad routing for my custom api so i say any request that comes in to slash api stand up agenda load my router so i'll have slash api stand up agenda slash meeting details or i'll have slash stand up dash topics like we we specified in our two handlers above now finally i just need to initialize the json um the json database uh inside of our our when the server starts so i'm going to do that by right after when we create the server right after it gets created i'm then going to call the init method which is going to say i want you to asynchronously calling it the file the the database is gonna be stored in a db folder in our project and then this is how we're going to do stringify and parsing and then there's the encoding that we have

Original Description

The meetings app will need primarily run client-side code within tabs in the Microsoft Teams client. However, we do have some requirements for server-side logic. To address this, we'll add an API to our web app that's hosting our meeting app. This video is part of a series in a playlist and is associated with a Microsoft Learning module: 'Create interactive meeting apps for Microsoft Teams'. Refer to the following URL to access the Microsoft Learning module for hands-on lab exercises and more resources: https://docs.microsoft.com/learn/modules/msteams-meetings-apps/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Microsoft 365 Developer · Microsoft 365 Developer · 0 of 60

← Previous Next →
1 Adaptive Cards community call-February 2019
Adaptive Cards community call-February 2019
Microsoft 365 Developer
2 PowerApps community call-February 2019
PowerApps community call-February 2019
Microsoft 365 Developer
3 Microsoft Graph community call-March 2019
Microsoft Graph community call-March 2019
Microsoft 365 Developer
4 Office Add ins community call-March 2019
Office Add ins community call-March 2019
Microsoft 365 Developer
5 PowerApps community call-March 2019
PowerApps community call-March 2019
Microsoft 365 Developer
6 Microsoft Teams community call-March 2019
Microsoft Teams community call-March 2019
Microsoft 365 Developer
7 Using React and Office UI Fabric React Components
Using React and Office UI Fabric React Components
Microsoft 365 Developer
8 Build Microsoft Teams customization using SharePoint Framework
Build Microsoft Teams customization using SharePoint Framework
Microsoft 365 Developer
9 Microsoft Graph community call-April 2019
Microsoft Graph community call-April 2019
Microsoft 365 Developer
10 Using Change Notifications and Track Changes with Microsoft Graph
Using Change Notifications and Track Changes with Microsoft Graph
Microsoft 365 Developer
11 Office Add Ins community call-April 2019
Office Add Ins community call-April 2019
Microsoft 365 Developer
12 Adaptive Cards community call-April 2019
Adaptive Cards community call-April 2019
Microsoft 365 Developer
13 Microsoft Teams community call-April 2019
Microsoft Teams community call-April 2019
Microsoft 365 Developer
14 Getting Started with Microsoft Graph and Application Registration
Getting Started with Microsoft Graph and Application Registration
Microsoft 365 Developer
15 Getting Started with Microsoft Graph and the Directory API
Getting Started with Microsoft Graph and the Directory API
Microsoft 365 Developer
16 Getting Started with Microsoft Graph and Microsoft Teams
Getting Started with Microsoft Graph and Microsoft Teams
Microsoft 365 Developer
17 Getting Started with Microsoft Graph Explorer
Getting Started with Microsoft Graph Explorer
Microsoft 365 Developer
18 Getting Started with Microsoft Graph
Getting Started with Microsoft Graph
Microsoft 365 Developer
19 Getting Started with Microsoft Graph and Mail API
Getting Started with Microsoft Graph and Mail API
Microsoft 365 Developer
20 Getting Started with Microsoft Graph and Office 365 Groups
Getting Started with Microsoft Graph and Office 365 Groups
Microsoft 365 Developer
21 Getting Started with Microsoft Graph and the Calendar API
Getting Started with Microsoft Graph and the Calendar API
Microsoft 365 Developer
22 Getting Started with the Microsoft Graph Toolkit
Getting Started with the Microsoft Graph Toolkit
Microsoft 365 Developer
23 Getting Started with Microsoft Graph and JavaScript SDKs
Getting Started with Microsoft Graph and JavaScript SDKs
Microsoft 365 Developer
24 Getting Started with Microsoft Graph and .NET SDKs
Getting Started with Microsoft Graph and .NET SDKs
Microsoft 365 Developer
25 Discover how businesses can be more productive with Microsoft 365 integrations
Discover how businesses can be more productive with Microsoft 365 integrations
Microsoft 365 Developer
26 Adaptive Cards community call-May 2019
Adaptive Cards community call-May 2019
Microsoft 365 Developer
27 Office Add-ins community call-May 2019
Office Add-ins community call-May 2019
Microsoft 365 Developer
28 Why We Built on Microsoft Teams
Why We Built on Microsoft Teams
Microsoft 365 Developer
29 Microsoft Teams community call-May 2019
Microsoft Teams community call-May 2019
Microsoft 365 Developer
30 Microsoft Graph community call-June 2019
Microsoft Graph community call-June 2019
Microsoft 365 Developer
31 Build Angular SPA's with Microsoft Graph - June 2019
Build Angular SPA's with Microsoft Graph - June 2019
Microsoft 365 Developer
32 Office Add -ins community call-June 2019
Office Add -ins community call-June 2019
Microsoft 365 Developer
33 Build Android native apps with the Microsoft Graph Android SDK - June 2019
Build Android native apps with the Microsoft Graph Android SDK - June 2019
Microsoft 365 Developer
34 Build MVC apps with Microsoft Graph - June 2019
Build MVC apps with Microsoft Graph - June 2019
Microsoft 365 Developer
35 Authenticate and connect with Microsoft Graph - June 2019
Authenticate and connect with Microsoft Graph - June 2019
Microsoft 365 Developer
36 Microsoft Graph data connect - June 2019
Microsoft Graph data connect - June 2019
Microsoft 365 Developer
37 Change notifications with Microsoft Graph - June 2019
Change notifications with Microsoft Graph - June 2019
Microsoft 365 Developer
38 Build iOS native apps with the Microsoft Graph REST API - June 2019
Build iOS native apps with the Microsoft Graph REST API - June 2019
Microsoft 365 Developer
39 Build Node.js Express apps with Microsoft Graph - June 2019
Build Node.js Express apps with Microsoft Graph - June 2019
Microsoft 365 Developer
40 Smart UI with Microsoft Graph - June 2019
Smart UI with Microsoft Graph - June 2019
Microsoft 365 Developer
41 Leveraging the Microsoft Graph API from the SharePoint Framework - June 2019
Leveraging the Microsoft Graph API from the SharePoint Framework - June 2019
Microsoft 365 Developer
42 Build UWP apps with Microsoft Graph - June 2019
Build UWP apps with Microsoft Graph - June 2019
Microsoft 365 Developer
43 Build React SPA's with Microsoft Graph - June 2019
Build React SPA's with Microsoft Graph - June 2019
Microsoft 365 Developer
44 Getting Started with Microsoft Graph and Batching
Getting Started with Microsoft Graph and Batching
Microsoft 365 Developer
45 Getting Started with Microsoft Graph and Change Notifications
Getting Started with Microsoft Graph and Change Notifications
Microsoft 365 Developer
46 Getting Started with Microsoft Graph and Consent Permissions
Getting Started with Microsoft Graph and Consent Permissions
Microsoft 365 Developer
47 Getting Started with Microsoft Graph and Education
Getting Started with Microsoft Graph and Education
Microsoft 365 Developer
48 Getting Started with Microsoft Graph and Financials
Getting Started with Microsoft Graph and Financials
Microsoft 365 Developer
49 Getting Started with Microsoft Graph and Excel
Getting Started with Microsoft Graph and Excel
Microsoft 365 Developer
50 Getting Started with Microsoft Graph and Data Connect
Getting Started with Microsoft Graph and Data Connect
Microsoft 365 Developer
51 Getting Started with Microsoft Graph and Intune
Getting Started with Microsoft Graph and Intune
Microsoft 365 Developer
52 Getting Started with Microsoft Graph and Notifications
Getting Started with Microsoft Graph and Notifications
Microsoft 365 Developer
53 Getting Started with Microsoft Graph and OneNote
Getting Started with Microsoft Graph and OneNote
Microsoft 365 Developer
54 Getting Started with Microsoft Graph and OneDrive
Getting Started with Microsoft Graph and OneDrive
Microsoft 365 Developer
55 Getting Started with Microsoft Graph and Open Extensions
Getting Started with Microsoft Graph and Open Extensions
Microsoft 365 Developer
56 Getting Started with Microsoft Graph and Paging
Getting Started with Microsoft Graph and Paging
Microsoft 365 Developer
57 Getting Started with Microsoft Graph and Schema Extensions
Getting Started with Microsoft Graph and Schema Extensions
Microsoft 365 Developer
58 Getting Started with Microsoft Graph and Security API
Getting Started with Microsoft Graph and Security API
Microsoft 365 Developer
59 Getting Started with Microsoft Graph and Query Parameters
Getting Started with Microsoft Graph and Query Parameters
Microsoft 365 Developer
60 Getting Started with Microsoft Graph and Reporting API
Getting Started with Microsoft Graph and Reporting API
Microsoft 365 Developer

This video teaches how to create an API endpoint for a meetings app using Azure AD MSAL Node package and Microsoft Graph, with a focus on authentication, authorization, and data storage. The API endpoint retrieves meeting details and stand-up topics from a JSON database. The video is part of a series and is relevant to beginners in AI news.

Key Takeaways
  1. Install required packages
  2. Create a new folder for the API
  3. Create a new file for authentication utilities
  4. Paste code for getting signing keys and validating tokens
  5. Validate token using jwt library
  6. Acquire token on behalf of user using Azure AD MSAL Node package
  7. Issue request to Microsoft Graph for chat endpoint and online meetings
  8. Retrieve meeting details and stand-up topics from JSON database
  9. Register API router with server
  10. Initialize JSON database
💡 Using Azure AD MSAL Node package to acquire tokens on behalf of users and validating tokens using the jwt library is crucial for secure authentication and authorization in API endpoint creation.

Related Reads

📰
When Tradition Meets Artificial Intelligence: The Future of Japanese Work Culture
Explore how AI is transforming traditional Japanese work culture and what this means for the future of business and society
Medium · AI
📰
Crypto Market Navigates Institutional Inflows and Innovation Amidst Rising AI Scam Threats and Valuation Deb Concerns
Learn how AI scam threats and valuation concerns impact crypto market navigation amidst institutional inflows and innovation
Dev.to AI
📰
IQE bets on AI data-centre demand to drive 20% sales growth in 2026
IQE expects 20% sales growth in 2026 driven by AI data-centre demand, learn how AI is transforming the semiconductor industry
The Next Web AI
📰
Judge signs off on Anthropic’s $1.5bn book piracy settlement, the biggest in US copyright history
Anthropic settles for $1.5bn in a copyright infringement case, the largest in US history, for training its Claude models on pirated books
The Next Web AI
Up next
Return-To-Office Mandates Are Backfiring Spectacularly
BusinessCringe
Watch →