Thomas Claudius Huber Trivadis Services AG Daten aus Office 365 in die eigene App integrieren
Thomas Claudius Huber Principal Consultant bei Trivadis Pluralsight-Autor, Buchautor C#, XAML, TypeScript, Azure www.thomasclaudiushuber.com @thomasclaudiush
Agenda 1. Was ist der Microsoft Graph? 2. App Registration & Security 3. Microsoft Graph in UWP-App nutzen
Die Welt ohne Microsoft Graph Unterschiedliche Endpunkte für Services wie Azure AD Outlook OneDrive Sharepoint Unterschiedliche Authentifizierung für Geschäfts-/Schulkonto Persönliches Konto
OneDrive https://api.onedrive.com/v1.0/drive OneDrive for Business https://contoso-my.sharepoint.com/personal/ user_contoso_com/_api/v2.0/drive Azure Active Directory Graph https://graph.windows.net/contoso.com/users https://graph.windows.net/contoso.com/groups Outlook Mail REST https://outlook.office.com/api/v2.0/me/messages & https://outlook.office.com/api/v2.0/me/events Windows Live Profile API https://apis.live.net/v5.0/me Persönliches Konto Sharepoint Profile API https://contoso.sharepoint.com/_api/sp.userpro files.peoplemanager/getmyproperties Exchange HD Picture API https://graph.microsoft.com/v1.0/me/photo Geschäfts-/Schulkonto Office Graph in Sharepoint Online https://contoso.sharepoint.com/_api/search/quer y?querytext='&properties=...
Microsoft Graph fasst die zig Endpunkte zu einem einzigen Endpunkt zusammen: https://graph.microsoft.com
Datenzugriff /me, /users, /groups, /messages, /drive,... Daten ablaufen /drive/items/<id> /lastmodifiedbyuser Auf Insights zugreifen Microsoft Graph /insights/trending Source: microsoft.com
Microsoft Graph Abfragen Get my profile Get my files Get my photo Get my mail Get my calendar Get my manager Get users in my organization Get people related to me Get my tasks Get my notes Get trending around me https://graph.microsoft.com/v1.0/me https://graph.microsoft.com/v1.0/me/drive/root/children https://graph.microsoft.com/v1.0/me/photo/$value https://graph.microsoft.com/v1.0/me/messages https://graph.microsoft.com/v1.0/me/calendar https://graph.microsoft.com/v1.0/me/manager https://graph.microsoft.com/v1.0/users https://graph.microsoft.com/beta/me/people https://graph.microsoft.com/beta/me/tasks https://graph.microsoft.com/beta/me/notes/notebooks https://graph.microsoft.com/beta/me/trendingaround
Microsoft Graph Abfrage-Muster https://graph.microsoft.com/{version}/{resource}?[odata_query_parameters] Stand heute gibt es zwei Versionen v1.0 für produktiven Einsatz beta für kommende APIs
Das Microsoft Graph Portal Enthält http://graph.microsoft.io - Dokumentation - Beispiele - SDKs - Graph Explorer zum Testen von Abfragen
DEMO Erste Schritte mit dem Microsoft Graph via http://graph.microsoft.io
OData Abfragen $select $expand $count $skip $orderby $filter $top $skiptoken https://graph.microsoft.io/docs/overview/query_parameters
OData-Metadaten OData stellt Metadaten zu Entitäten und Aktionen als XML-Datei bereit https://graph.microsoft.com/v1.0/$metadata https://graph.microsoft.com/beta/$metadata
DEMO Metadaten einsehen und verstehen
Aktionen ausführen Metadaten enthalten auch Actions Dateien erstellen, löschen, verschieben,... Excel-Dateien navigieren, aktualisieren, speichern,... Mails erstellen, versenden, beantworten,...
DEMO Eine Mail versenden
Agenda 1. Was ist der Microsoft Graph? 2. App Registration & Security 3. Microsoft Graph in UWP-App nutzen
Quelle: https://graph.microsoft.io/docs
Was muss man tun 1. App registrieren 2. OpenID Connect / OAuth2 verwenden 3. Auf Microsoft Graph zugreifen
App registrieren http://dev.office.com/app-registration Funktioniert für Geschäfts-/Schulkonto, nicht für persönliches Konto V2.0: http://apps.dev.microsoft.com - Wird für Azure AD v2.0-endpunkt verwendet - Funktioniert für Geschläfts-/Schulkonto UND für persönliches Konto - https://azure.microsoft.com/documentation/articles /active-directory-v2-limitations/
Azure AD v2.0 Endpunkt aufrufen Für OpenID Connect / OAuth2 sind diverse Libraries verfügbar Oder manuell via v2.0 Endpunkt https://login.microsoftonline.com/common/oauth2/v2.0/authorize https://login.microsoftonline.com/common/oauth2/v2.0/token
Den Authorize-Endpunkt manuell aufrufen
Testen mit dieser URL https://login.microsoftonline.com/common/oauth2/v2.0/authorize? client_id=enter_app_id &scope=openid+profile &response_type=id_token &redirect_uri=https://localhost &nonce=enter_random_number_here JSON Web Token (JWT) anschauen: http://calebb.net/
Wenn Du nicht Chuck Norris bist:
Wenn Du nicht Chuck Norris Dominic Baier bist: Nur zum Testen manuell aufrufen Ansonsten eine Library / SDK verwenden Azure AD Authentication Libary (ADAL) Microsoft Authentication Library (MSAL)... NuGet: Microsoft.Identity.Client (preview for.net) Dominic s Session zu OpenID Connect / OAuth2: 21. Sept, 16:15-17:30, Gutenberg 1
Agenda 1. Was ist der Microsoft Graph? 2. App Registration & Security 3. Microsoft Graph in UWP-App nutzen
REST oder SDK? SDK via NuGet: Microsoft.Graph OAuth2: Microsoft.Identity.Client (noch in Preview) Samples unter github.com/microsoftgraph Enthalten AuthenticationHelper-Klasse Zeigen sowohl REST als auch SDK
OneDrive Daten abrufen
OneDrive Daten abrufen var graphclient = AuthenticationHelper.GetAuthenticatedClient(); var request = graphclient.me.drive.root.search(".jpg").request().top(10); var collection = await request.getasync();
Inhalt eines Bildes abrufen var graphclient = AuthenticationHelper.GetAuthenticatedClient(); var request = graphclient.me.drive.items[selecteditem.id].content.request(); var stream = await request.getasync();
Mail versenden var request = graphclient.me.sendmail( message, false).request(); await request.postasync();
Agenda 1. Was ist der Microsoft Graph? 2. App Registration & Security 3. Microsoft Graph in UWP-App nutzen
Summary
Microsoft Graph vs. spezifische API Der Microsoft Graph ist eine Facade Im Hintergrund werden spezifische APIs aufgerufen, bspw. Onedrive: https://api.onedrive.com/v1.0/drive Outlook: https://outlook.office.com/api/v2.0/me/messages... Spezifische API nur dann verwenden, wenn Funktion in Microsoft Graph nicht vorhanden ist
Summary Microsoft Graph vereinheitlicht Zugriff auf O365-Daten Integration in die eigene App gestaltet sich simpel Es existieren zahlreiche SDKs REST-APIs lassen sich auch ohne SDK auf jeder Plattform aufrufen
Info / Resourcen Kontakt Thomas @thomasclaudiush thomas.huber@trivadis.com www.thomasclaudiushuber.com Session-Inhalt: www.thomasclaudiushuber.com/talks Office 365 Demo-Umgebung anlegen: - http://demos.microsoft.com - Graph Samples: http://github.com/microsoftgraph