SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer
-
Upload
sebastien-levert -
Category
Technology
-
view
296 -
download
3
Transcript of SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer
Everything you need to know about the Microsoft Graph as a
SharePoint DeveloperSharePoint Saturday Utah
Sébastien Levert
Who’s that guy ?
@sebastienlevert | http://sebastienlevert.com | Product Evangelist & Partner Manager at
Agenda
Introduction
Building integration with Office 365
What is the Microsoft Graph?
Single endpoint for:
1 - Accessing data/me, /users, /groups, /messages, /drive, ….
2 - Traversing data/drive/<id>/lastmodifiedByUser
3 - Accessing insights/insights/trending
4- Work/School and Personal
https://graph.microsoft.com/
Use the Microsoft Graph to build smart appsGateway to data and insights in Office365
Easy traversal of objects and rich
relationships
Web Standards, Open Platform Secure data
accessOAuth2.0OpenID ConnectRESTJSON
Authentication & Authorization
Azure AD Application
• Proxy to you Office 365 data• Enable user-consent to be
transparent with the way the application will play with the data• Secure protocol• OpenID Connect and OAuth
2.0• No capturing user
credentials• Fine-grained access scopes• Long-term access through
refresh tokens
Permissions
• Application permissions• Act on the Microsoft Graph as a Deamon• Authentication is certificate-based
• Delegated permissions• Act on the Microsoft Graph as an authenticated user• 60+ delegated permissions• Does not replace the actual permissions on the data
Implicit Flow
Azure AD
Client Application Microsoft Graph
1
2
3
4
Token
Token
Ressources
Let’s play
Acting on the graph
• Getting Graph data• Creating Graph data• Updating Graph data• Deleting Graph data• Executing actions on the Graph
Acting on the Graph
GET https://graph.microsoft.com/v1.0/me
POST https://graph.microsoft.com/v1.0/groups{ …}
PATCH https://graph.microsoft.com/v1.0/groups/<id>
DELETE https://graph.microsoft.com/v1.0/groups/<id>
POST https://graph.microsoft.com/v1.0/me/sendMail
Exploring the Graph
• Using the Graph Explorer• Using REST HTTP Calls• Using .NET• Using PnP PowerShell• Using JavaScript• Using the SDKs
Using the Graph Explorer
Using REST HTTP Calls
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJub25j…Accept: application/json
GET https://graph.microsoft.com/v1.0/meGET https://graph.microsoft.com/v1.0/me/messagesGET https://graph.microsoft.com/v1.0/me/drive/root/childrenGET https://graph.microsoft.com/v1.0/groups?$filter=groupTypes/any(c:c+eq+'Unified')GET https://graph.microsoft.com/beta/me/trendingAroundGET https://graph.microsoft.com/beta/me/plans
Using REST HTTP Calls (SharePoint)
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJub25j…Accept: application/json
GET https://graph.microsoft.com/beta/sharePoint/sitesGET https://graph.microsoft.com/beta/sharePoint/siteGET https://graph.microsoft.com/beta/sharePoint:/site/labGET https://graph.microsoft.com/beta/sharePoint/site/listsGET https://graph.microsoft.com/beta/sharePoint/site/lists/<id>/itemsGET https://graph.microsoft.com/beta/sharePoint/site/drivesGET https://graph.microsoft.com/beta/sharePoint/site/lists/<id>/driveGET https://graph.microsoft.com/beta/sharePoint/site/lists/<id>/drive/root/children
Using .NET
var me = graphServiceClient.Me.Request().GetAsync();
var calendar = await graphServiceClient .Me.Calendar.Request().Select("id").GetAsync();
var children = await graphServiceClient .Me .Drive .Root .Children .Request() .Expand("thumbnails") .GetAsync();
var children = await graphServiceClient .Me .Drive .Items[itemId] .Children .Request() .Expand("thumbnails") .GetAsync();
Using PnP PowerShell
Connect-PnPMicrosoftGraph -Scopes @("Group.ReadWrite.All")
Get-PnPUnifiedGroup
$group = New-PnPUnifiedGroup -DisplayName "SPS Utah" ` -Description "SPS Utah" ` -MailNickname "spsutah"
Remove-PnPUnifiedGroup -Identity $group.GroupId
Using JavaScript
// construct the email objectconst mail = { subject: "Microsoft Graph JavaScript Sample", toRecipients: [{ emailAddress: { address: "[email protected]" } }], body: { content: "<h1>MicrosoftGraph JavaScript Sample</h1>Check out https://github.com/microsoftgraph/msgraph-sdk-javascript", contentType: "html" }}
client .api('/users/me/sendMail') .post({message: mail}, (err, res) => { console.log(res) })
Using the SDKs
Be notified by the Graph• Webhooks
Creating a webhook on the Graph
POST https://graph.microsoft.com/beta/subscriptions
{ "changeType": "Created", "notificationUrl": "https://<url>/api/webhookCallback", "resource": "me/messages"}
Being notified from a webhook
POST https://<url>/api/webhookCallback
{ "value":[ { "subscriptionId":"7f105c7d-2dc5-4530-97cd-4e7af6534c07", "subscriptionExpirationDateTime":"2015-11-20T18:23:45.9356913Z", "changeType":"Created", "resource":"Users/<user-id>/messages/<message-id>", "resourceData":{ "@odata.type":"#Microsoft.Graph.Message", "@odata.id":"Users/<user-id>/messages/<message-id>", "@odata.etag":"W/\"CQAAABYAAACoeN6SYXGLRrvRm+CYrrfQAACvvGdb\"", "Id“:"<message-id>" } } ]}
Extending the Graph• Open type extensions• Schema extensions
Open type extensions
POST https://graph.microsoft.com/beta/me/contacts/ID/extensions
{ "@odata.type": "Microsoft.Graph.OpenTypeExtension", "extensionName": "Contacts.Extensions.LinkedIn", "linkedInUrl": "https://www.linkedin.com/in/seb/"}
Defining a schema extension
POST https://graph.Microsoft.com/beta/schemaExtensions
{ "id": "linkedin_information", "description": "All information about LinkedIn account", "targetType": ["Contacts"], "available": "Online", "properties" : [ "name": "linkedInUrl", "type": "String" ]}
Adding a schema extension data
POST https://graph.microsoft.com/beta/me/contacts/ID
{ "linkedin_information": { "linkedInUrl": "https://www.linkedin.com/in/seb/" }}
Next Steps
Resources
• https://dev.office.com• https://graph.microsoft.io• https://channel9.msdn.com/Events/Connect/2016/213• https://techcommunity.microsoft.com/t5/Microsoft-
Ignite-Content/BRK4016-Access-SharePoint-files-and-lists-using-SharePoint-API/td-p/10403• https://mva.microsoft.com/product-training/office-
development
Samples
• https://github.com/SharePoint/PnP-PowerShell• https://github.com/microsoftgraph/msgraph-sdk-
javascript• https://github.com/sebastienlevert/officehub
Share your experience
• Use hashtags to share your experience• #Office365Dev• #MicrosoftGraph
• Contribute and ask question to the Microsoft Tech Community• https://slevert.me/tech-community-sp-dev
• Log issues & questions to the GitHub Repositories
Thank you!
@sebastienlevert | http://sebastienlevert.com | Product Evangelist & Partner Manager at