SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

34
Everything you need to know about the Microsoft Graph as a SharePoint Developer SharePoint Saturday Utah Sébastien Levert

Transcript of SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Page 1: 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

Page 2: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Who’s that guy ?

@sebastienlevert | http://sebastienlevert.com | Product Evangelist & Partner Manager at

Page 3: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Agenda

Page 4: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Introduction

Page 5: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Building integration with Office 365

Page 6: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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/

Page 7: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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

Page 8: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Authentication & Authorization

Page 9: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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

Page 10: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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

Page 11: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Implicit Flow

Azure AD

Client Application Microsoft Graph

1

2

3

4

Token

Token

Ressources

Page 12: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Let’s play

Page 13: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Acting on the graph

• Getting Graph data• Creating Graph data• Updating Graph data• Deleting Graph data• Executing actions on the Graph

Page 14: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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

Page 15: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Exploring the Graph

• Using the Graph Explorer• Using REST HTTP Calls• Using .NET• Using PnP PowerShell• Using JavaScript• Using the SDKs

Page 16: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Using the Graph Explorer

Page 17: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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

Page 18: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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

Page 19: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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();

Page 20: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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

Page 21: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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) })

Page 22: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Using the SDKs

Page 23: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Be notified by the Graph• Webhooks

Page 24: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Creating a webhook on the Graph

POST https://graph.microsoft.com/beta/subscriptions

{ "changeType": "Created", "notificationUrl": "https://<url>/api/webhookCallback", "resource": "me/messages"}

Page 25: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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>" } } ]}

Page 26: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Extending the Graph• Open type extensions• Schema extensions

Page 27: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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/"}

Page 28: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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" ]}

Page 29: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Adding a schema extension data

POST https://graph.microsoft.com/beta/me/contacts/ID

{ "linkedin_information": { "linkedInUrl": "https://www.linkedin.com/in/seb/" }}

Page 30: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Next Steps

Page 31: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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

Page 32: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Samples

• https://github.com/SharePoint/PnP-PowerShell• https://github.com/microsoftgraph/msgraph-sdk-

javascript• https://github.com/sebastienlevert/officehub

Page 33: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

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

Page 34: SPS Utah - Everything your need to know about the Microsoft Graph as a SharePoint developer

Thank you!

@sebastienlevert | http://sebastienlevert.com | Product Evangelist & Partner Manager at