This blog will cover how to create a lightweight application that will Create, Read, Update and Delete user profile data in Microsoft Graph by extending the “user” resource.
Firstly, let us cover what exactly Graph Extensions are.
Graph Extensions allow us to extend several graph resources,
such as “user” and “message”, to capture additional data that we may need for
our own application, without having to rely on an external data source.
One benefit of using Graph Extensions over methods such as
local storage is the roaming capability. Also, because the application
properties are stored in the Graph, they can be leveraged across the whole
Microsoft 365 platform.
Because I am an aviation geek we will use “favorite aircraft” as an example scenario. Here is the high-level objective.
- A user can create, read, update and delete a property named “plane”
- The selection is saved as an extended property in the Microsoft Graph.
Getting started
Because we are interacting with the Microsoft Graph, we need
to set-up an application registration in Microsoft Azure where we can define
settings such as API permissions.
Application Registration
Open Microsoft Azure and navigate to “Azure Active Directory”.
Click on “App registrations” and then select “New registration”.
Input a name for the application and select “Accounts in this organizational directory only”.
Within the redirect URI field input “https://global.consent.azure-apim.net/redirect” before clicking “Register”.
Once the application registration has been created, copy the “Application (client) ID” for later use.
Generate a “client secret” that never expires and copy the value for later use.
Within the API permissions add “User.ReadWrite” as a
delegated permission from the Microsoft Graph.
Two permissions should now be listed:
- User.Read
- User.ReadWrite
Click on “Grant admin consent for *Org Name*”
That should be everything we need to do within Microsoft Azure, next navigate to PowerApps.
Custom Connectors
Expand the “Data” navigation drop-down and select “Custom Connectors”.
Click on “New custom connector” followed by “Create from blank”.
Input a name and then click on “Continue”.
What follows are four different areas for configuration;
General, Security, Definition and Test.
General
Within the “Host” field insert “graph.microsoft.com”.
Security
Within the “Authentication type” drop-down, select “OAuth
2.0” and then select “Azure Active Directory”.
Insert the “Client id” and “Client secret” we copied from the previous steps.
Within the “Resource URL” insert “https://graph.microsoft.com”.
Definition
Within the definition area we will create four actions for Create,
Read, Update and Delete.
The Microsoft Graph Explorer is a great resource for simulating API calls and anticipating the responses. This tool is particularly useful for the following section, therefore please test each API call here before creating the following actions.
Create
Click on “New action”.
Give the action a “Summary”, “Description” and “Operation
ID”.
Summary |
Create Favorite Plane |
Description |
Create Favorite Plane |
Operation
ID |
CreateFavoritePlane |
Within the “Request” section click on “Import from sample” and copy the following values.
Verb |
POST |
URL |
/v1.0/me/extensions |
Headers |
|
Body |
{ "@odata.type": "microsoft.graph.openTypeExtension", "extensionName":
"com.bestranet.roamingSettings", "plane": "Concorde" } |
Within the toolbar click on “Create connector”.
You should now be able to test the action. To test the action, you will need to use a connection. If there are no existing connections, the custom connector may close to establish one. If this is the case, simply re-open the custom connector.
Read
Click on “New action”.
Give the action a “Summary”, “Description” and “Operation
ID”.
Summary |
Read Favorite Plane |
Description |
Read Favorite Plane |
Operation
ID |
ReadFavoritePlane |
Within the “Request” section click on “Import from sample” and copy the following values.
Verb |
GET |
URL |
/v1.0/me?$select=id,displayName&$expand=extensions |
Headers |
|
Within the “Response” section click on “Add default response” and copy the following values.
Headers |
|
Body |
Paste from
the response issued in Microsoft Graph Explorer |
Within the toolbar click on “Update connector”.
You should now be able to test the action.
Update
Click on “New action”.
Give the action a “Summary”, “Description” and “Operation
ID”.
Summary |
Update Favorite Plane |
Description |
Update Favorite Plane |
Operation
ID |
UpdateFavoritePlane |
Within the “Request” section click on “Import from sample” and copy the following values.
Verb |
PATCH |
URL |
/v1.0/me/extensions/com.bestranet.roamingSettings |
Headers |
|
Body |
{ "plane": "Concorde" } |
Within the toolbar click on “Update connector”.
You should now be able to test the action.
Delete
Click on “New action”.
Give the action a “Summary”, “Description” and “Operation
ID”.
Summary |
Delete Favorite Plane |
Description |
Delete Favorite Plane |
Operation
ID |
DeleteFavoritePlane |
Within the “Request” section click on “Import from sample” and copy the following values.
Verb |
DELETE |
URL |
/v1.0/me/extensions/com.bestranet.roamingSettings |
Headers |
|
Body |
|
Within the toolbar click on “Update connector”.
You should now be able to test the action.
Assuming all four CRUD actions within the custom connector have been successfully tested we may now proceed to create the canvas app.
Canvas App
Create and configure a canvas app that contains four
buttons, a combo box control and a label.
Associate the custom connector we created previously as a data source to the app.
Configure each of the controls as follows.
Combo Box
Control
Name |
FavoritePlaneChoice |
Items |
["Concorde","Jumbo
Jet","Bi Plane"] |
SelectMultiple |
false |
IsSearchable |
false |
NoSelectionText |
Favorite
Plane |
Label
Control
Name |
FavoritePlaneLbl |
Text |
"My
Favorite Plane is " & First(favoritePlane.extensions).plane &
"!" |
Control
Name |
CreateFavoritePlaneBtn |
Text |
Create
Favorite |
OnSelect |
GraphExtensionConnector.CreateFavoritePlane({'@odata.type':"microsoft.graph.openTypeExtension",
extensionName:"com.bestranet.roamingSettings",
plane:FavoritePlaneChoice.Selected.Value}) |
Control
Name |
ReadFavoritePlaneBtn |
Text |
Read Favorite |
OnSelect |
Set(favoritePlane,
GraphExtensionConnector.ReadFavoritePlane({'$select':"id,
displayName", '$expand': "extensions"})) |
Control
Name |
UpdateFavoritePlaneBtn |
Text |
Update
Favorite |
OnSelect |
GraphExtensionConnector.UpdateFavoritePlane({plane:FavoritePlaneChoice.Selected.Value}) |
Control
Name |
DeleteFavoritePlaneBtn |
Text |
Delete
Favorite |
OnSelect |
GraphExtensionConnector.DeleteFavoritePlane() |
Finally, play the app!
Assuming everything works correctly you should be able to
Create, Read, Update and Delete your favorite plane from the Microsoft Graph as
an extended property. Try from multiple devices and you will see the property
roams with you, whichever device is used.
Although this blog is more centred towards PowerApps, the
custom property we created for favorite plane can now be leveraged from
multiple areas of the Microsoft 365 platform.
Perhaps my next blog will be using a SPFx web part to display this property on SharePoint.
I liked your work and the way in which you have shared this article here about Microsoft 365 Power Automate. It is a beneficial and helpful article for us. Thanks for sharing an article like this. Keep it up.
ReplyDelete888casino Review and Bonus Code for 2021
ReplyDeleteThe 888 Casino 충청남도 출장안마 Review: 김포 출장안마 The Ultimate Guide 제천 출장안마 to 888casino. Check out the Games, Bonuses, Payments and Security; Deposit Limits; Software; Software Rating: 제주 출장샵 3.8 · Review by Dr 서울특별 출장샵
Euro Palace designed lots of its online slots to resemble conventional slots from the early 1800s. For instance, the Reel slots sport provides a simplistic design with cherries, gold bars, and 7s that take you again to much less complicated} time. What makes Ruby Fortune probably the greatest locations half in} online slots is its respected customer support staff and safe encryption. Royal Vegas certainly one of the|is amongst the|is likely one of the} finest online playing sites for those who|for many who|for individuals who} practice accountable playing. By using the "Responsible Gaming Features" on the login web page, players can set up deposit limits on a monthly 카지노사이트 or weekly foundation. This function also lets you set deadlines half in} and taking breaks.
ReplyDelete