SharePoint Saturday Belgium 2017 • October 21 • Brussels Track: DEVELOPER| Level: 300
Microsoft Graph with ASP.NET
MVC
Donald Hessing (MCM)
PlatinumGoldSilver
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Who am I?
• Donald Hessing
• Microsoft Lead Architect – Digital Customer
Experience – Capgemini Netherlands
• Microsoft Certified Master(MCM) for SharePoint
• Speaker Chair for ESPC17
• @dhessing
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Agenda
• Short Introduction to the Microsoft Graph
• Microsoft Graph SDK
• Extensions (Open and Schema)
• Webhooks
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Before Microsoft Graph
• Each service has its own set of APIs, characteristics, data model, and authentication
• Separate authentication stack for work and personal accounts
• High learning curve - not always compatible with non Microsoft stack
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Single endpoint for Office 365 Services
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Unified API Style
Operation Service Endpoint
GET my profile https://graph.microsoft.com/v1.0/me
GET my files https://graph.microsoft.com/v1.0/drive/root/children
GET my photo https://graph.microsoft.com/v1.0/photo/$value
GET my mail https://graph.microsoft.com/v1.0/me/messages
GET my calendar https://graph.microsoft.com/v1.0/me/calendar
GET my manager https://graph.microsoft.com/v1.0/me/manager
GET group conversations https://graph.microsoft.com/v1.0/groups/<id>/conversations
GET files trending around me https://graph.microsoft.com/v1.0/me/insights/trending
https://graph.microsoft.com
SharePoint Saturday Belgium 2017 • October 21 • Brussels
What has become GA over the last year?
• Azure Active Directory
• Outlook mail, Calendar and Contacts
• Office 365 Groups and Conversations
• OneDrive Drives and Files
• WebHooks for Outlook, Groups, User,
OneDrive data
• SharePoint & LiveID profiles
• Office 365 Reports
• Extensions
• Excel API
• FindMeetingTime
• Planner
• Extensions
• Delta Queries
• Sites (SharePoint)
https://developer.microsoft.com/en-
us/graph/docs/concepts/changelog
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Authentication
ADAL v1.0
• Authentication library to deal with Azure
Active Directory authentication flow
• Support for Work and School accounts via
Azure Active Directory
• Full set of SDKs available
• Supports Office 365 Services
• User gives consent for all permissions at first
start
MSAL v2.0
• Unified authentication library to deal with
authentication across the different identity
platforms provided by Microsoft
• Support for Work, School and Personal
accounts – No Azure requirement
• User gives consent when the applications
needs it
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Revoke User Consent
Native Application
• Consent is part of the Refresh Token and typically stored on the device
• Revoke Consent typically means uninstalling the application or clear the
TokenCache
Web Server Applications
• Consent is stored in Azure Active Directory and not part of the Refresh
Token
• User can Revoke Consent at
https://account.activedirectory.windowsazure.com
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Authentication flow for Microsoft Graph
SharePoint Saturday Belgium 2017 • October 21 • Brussels
DEMO
Application registration and Starter project
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Microsoft Graph API SDK
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Microsoft Graph API SDK
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Getting started
https://www.nuget.org/packages/Microsoft.Graph
1.4.0
SharePoint Saturday Belgium 2017 • October 21 • Brussels
SDK Query Model
• Implements the ODATA behaviour and signatures as methods on the
Request
.Select() -> $select
.Filter() -> $filter
.OrderBy() -> $orderby
.Expand() -> $expand
• Provides paging capabilities
• Through NextPageRequest property on query results/collections
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Working with resources
• Graph SDK implements support for managing the Graph Resources:
.GetAsync() -> GET
.AddAsync()-> POST
.UpdateAsync()-> PATCH
.PutAsync() -> PUT
DeleteAsync() -> DELETE
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Microsoft Graph ASP.NET SDK Example
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Create Group
SharePoint Saturday Belgium 2017 • October 21 • Brussels
DEMO
Demo Microsoft Graph SDK for .NET
https://github.com/SharePoint/PnP/tree/master/Samples/MicrosoftGraph.Office365.DotNetSDK
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Extensions
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Supported resources for Extensions
• When using personal accounts (MSAL) you are limited to
the event, post, group, message, contact, and user resources
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Extensions
• Add Custom Properties to Microsoft Graph Resources without
requiring an external data source
MS Graph Group Data
Custom Extension Data
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Type of Extensions
Open Extensions (aka Office 365 data extensions):
• Untyped data that is scoped to the tenant
• extensionName property should be unique within the tenant
• Naming convention: Com.Capgemini.ManagedEvent for the Capgemini.Com
tenant
Schema Extensions
• Strongly typed data – define your own schema extension definition
• Schema extension definition should have a unique name for its id:
• By using the an existing vanity domain that is verified with your tenant (e.g. capgemini.com)
for capgemini_ManagedEvent
• By using a name without a domain , e.g. ManagedEvent. The id will be based on the schema
name and prefixed with 8 random characters. E.g. extabcdefgh_ManagedEvent
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Schema Extensions Lifecycle
State LifeCycle state behaviour
InDevelopment • Initial state – the owner app is still developing the schema extension.
• The owner app can move the extension from InDevelopment to the Available state
Available • The schema extension is available for use by all apps in any tenant.
• Only the owner app can update the extension definition with additive changes
• The owner app can move the schema extension from Available to the Deprecated state
Deprecated • The schema extension definition can no longer be read or modified.
• Apps can, however, still read, update, or delete existing extension property values
• The owner app can move the schema extension from Deprecated back to the Available
state (*)
(*) Fixed! Make sure you have the latest bits..
SharePoint Saturday Belgium 2017 • October 21 • Brussels
DEMO
Extensions
MS Graph Group Data
Custom Extension Data
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Webhooks
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Webhooks
• Microsoft Graph REST API clients can subscribe to changes on the following
resources:
• Messages
• Events
• Contacts
• Group conversations
• Drive root items
• After Microsoft Graph accepts the subscription request, it pushes
notifications to the URL specified in the subscription.
• The app then takes action according to its business logic. For example, it
fetches more data, updates cache and views, etc.
SharePoint Saturday Belgium 2017 • October 21 • Brussels
3. NOTIFY2. VALIDATE
/subscriptions
/notifications
1. CREATE
Outlook Apps
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Example Notification API
SharePoint Saturday Belgium 2017 • October 21 • Brussels
NGROK
• Webhook requires a public accessible endpoint for sending the notifications
• During development, your endpoint is running on https://localhost:[portnumber]
• Use NGROK to:
• Create a public accessible endpoint
• Tunnel the request from the public endpoint to https://localhost:[portnumber]
SharePoint Saturday Belgium 2017 • October 21 • Brussels
Thank You!
Feedback
http://spsbe.be

Microsoft Graph with ASP.NET MVC

  • 1.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Track: DEVELOPER| Level: 300 Microsoft Graph with ASP.NET MVC Donald Hessing (MCM)
  • 2.
  • 3.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Who am I? • Donald Hessing • Microsoft Lead Architect – Digital Customer Experience – Capgemini Netherlands • Microsoft Certified Master(MCM) for SharePoint • Speaker Chair for ESPC17 • @dhessing
  • 4.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Agenda • Short Introduction to the Microsoft Graph • Microsoft Graph SDK • Extensions (Open and Schema) • Webhooks
  • 5.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Before Microsoft Graph • Each service has its own set of APIs, characteristics, data model, and authentication • Separate authentication stack for work and personal accounts • High learning curve - not always compatible with non Microsoft stack
  • 6.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Single endpoint for Office 365 Services
  • 7.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Unified API Style Operation Service Endpoint GET my profile https://graph.microsoft.com/v1.0/me GET my files https://graph.microsoft.com/v1.0/drive/root/children GET my photo https://graph.microsoft.com/v1.0/photo/$value GET my mail https://graph.microsoft.com/v1.0/me/messages GET my calendar https://graph.microsoft.com/v1.0/me/calendar GET my manager https://graph.microsoft.com/v1.0/me/manager GET group conversations https://graph.microsoft.com/v1.0/groups/<id>/conversations GET files trending around me https://graph.microsoft.com/v1.0/me/insights/trending https://graph.microsoft.com
  • 8.
    SharePoint Saturday Belgium2017 • October 21 • Brussels What has become GA over the last year? • Azure Active Directory • Outlook mail, Calendar and Contacts • Office 365 Groups and Conversations • OneDrive Drives and Files • WebHooks for Outlook, Groups, User, OneDrive data • SharePoint & LiveID profiles • Office 365 Reports • Extensions • Excel API • FindMeetingTime • Planner • Extensions • Delta Queries • Sites (SharePoint) https://developer.microsoft.com/en- us/graph/docs/concepts/changelog
  • 9.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Authentication ADAL v1.0 • Authentication library to deal with Azure Active Directory authentication flow • Support for Work and School accounts via Azure Active Directory • Full set of SDKs available • Supports Office 365 Services • User gives consent for all permissions at first start MSAL v2.0 • Unified authentication library to deal with authentication across the different identity platforms provided by Microsoft • Support for Work, School and Personal accounts – No Azure requirement • User gives consent when the applications needs it
  • 10.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Revoke User Consent Native Application • Consent is part of the Refresh Token and typically stored on the device • Revoke Consent typically means uninstalling the application or clear the TokenCache Web Server Applications • Consent is stored in Azure Active Directory and not part of the Refresh Token • User can Revoke Consent at https://account.activedirectory.windowsazure.com
  • 11.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Authentication flow for Microsoft Graph
  • 12.
    SharePoint Saturday Belgium2017 • October 21 • Brussels DEMO Application registration and Starter project
  • 13.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Microsoft Graph API SDK
  • 14.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Microsoft Graph API SDK
  • 15.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Getting started https://www.nuget.org/packages/Microsoft.Graph 1.4.0
  • 16.
    SharePoint Saturday Belgium2017 • October 21 • Brussels SDK Query Model • Implements the ODATA behaviour and signatures as methods on the Request .Select() -> $select .Filter() -> $filter .OrderBy() -> $orderby .Expand() -> $expand • Provides paging capabilities • Through NextPageRequest property on query results/collections
  • 17.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Working with resources • Graph SDK implements support for managing the Graph Resources: .GetAsync() -> GET .AddAsync()-> POST .UpdateAsync()-> PATCH .PutAsync() -> PUT DeleteAsync() -> DELETE
  • 18.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Microsoft Graph ASP.NET SDK Example
  • 19.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Create Group
  • 20.
    SharePoint Saturday Belgium2017 • October 21 • Brussels DEMO Demo Microsoft Graph SDK for .NET https://github.com/SharePoint/PnP/tree/master/Samples/MicrosoftGraph.Office365.DotNetSDK
  • 21.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Extensions
  • 22.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Supported resources for Extensions • When using personal accounts (MSAL) you are limited to the event, post, group, message, contact, and user resources
  • 23.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Extensions • Add Custom Properties to Microsoft Graph Resources without requiring an external data source MS Graph Group Data Custom Extension Data
  • 24.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Type of Extensions Open Extensions (aka Office 365 data extensions): • Untyped data that is scoped to the tenant • extensionName property should be unique within the tenant • Naming convention: Com.Capgemini.ManagedEvent for the Capgemini.Com tenant Schema Extensions • Strongly typed data – define your own schema extension definition • Schema extension definition should have a unique name for its id: • By using the an existing vanity domain that is verified with your tenant (e.g. capgemini.com) for capgemini_ManagedEvent • By using a name without a domain , e.g. ManagedEvent. The id will be based on the schema name and prefixed with 8 random characters. E.g. extabcdefgh_ManagedEvent
  • 25.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Schema Extensions Lifecycle State LifeCycle state behaviour InDevelopment • Initial state – the owner app is still developing the schema extension. • The owner app can move the extension from InDevelopment to the Available state Available • The schema extension is available for use by all apps in any tenant. • Only the owner app can update the extension definition with additive changes • The owner app can move the schema extension from Available to the Deprecated state Deprecated • The schema extension definition can no longer be read or modified. • Apps can, however, still read, update, or delete existing extension property values • The owner app can move the schema extension from Deprecated back to the Available state (*) (*) Fixed! Make sure you have the latest bits..
  • 26.
    SharePoint Saturday Belgium2017 • October 21 • Brussels DEMO Extensions MS Graph Group Data Custom Extension Data
  • 27.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Webhooks
  • 28.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Webhooks • Microsoft Graph REST API clients can subscribe to changes on the following resources: • Messages • Events • Contacts • Group conversations • Drive root items • After Microsoft Graph accepts the subscription request, it pushes notifications to the URL specified in the subscription. • The app then takes action according to its business logic. For example, it fetches more data, updates cache and views, etc.
  • 29.
    SharePoint Saturday Belgium2017 • October 21 • Brussels 3. NOTIFY2. VALIDATE /subscriptions /notifications 1. CREATE Outlook Apps
  • 30.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Example Notification API
  • 31.
    SharePoint Saturday Belgium2017 • October 21 • Brussels NGROK • Webhook requires a public accessible endpoint for sending the notifications • During development, your endpoint is running on https://localhost:[portnumber] • Use NGROK to: • Create a public accessible endpoint • Tunnel the request from the public endpoint to https://localhost:[portnumber]
  • 32.
    SharePoint Saturday Belgium2017 • October 21 • Brussels Thank You!
  • 33.