36
Thomas Claudius Huber | Trivadis Services AG Daten aus Office 365 in die eigene App integrieren

Daten aus Office 365 in die eigene App integrieren...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

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

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

• Unterschiedliche Authentifizierung für

– Geschäfts-/Schulkonto

– Persönliches Konto

Azure AD Outlook OneDrive Sharepoint

Geschäfts-/SchulkontoPersönliches Konto

Outlook Mail REST

https://outlook.office.com/api/v2.0/me/Messages & https://outlook.office.com/api/v2.0/me/Events

OneDrive

https://api.onedrive.com/v1.0/drive

OneDrive for Business

https://contoso-my.sharepoint.com/personal/

user_contoso_com/_api/v2.0/drive

Windows Live Profile API

https://apis.live.net/v5.0/me

Sharepoint Profile API

https://contoso.sharepoint.com/_api/SP.UserPro

files.PeopleManager/GetMyProperties

Azure Active Directory Graph

https://graph.windows.net/contoso.com/users

https://graph.windows.net/contoso.com/groups

Exchange HD Picture API

https://graph.microsoft.com/v1.0/me/photo

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

Microsoft Graph

• Datenzugriff

– /me, /users,

/groups, /messages,

/drive, ...

• Daten ablaufen

– /drive/items/<id>

/lastmodifiedByUser

• Auf Insights zugreifen

– /insights/trending Source: microsoft.com

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 Abfragen

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

http://graph.microsoft.ioEnthält

- Dokumentation

- Beispiele

- SDKs

- Graph Explorer zum Testen von Abfragen

DEMOErste Schritte mit dem Microsoft Graph

via http://graph.microsoft.io

OData Abfragen

https://graph.microsoft.io/docs/overview/query_parameters

$select

$orderby

$expand

$filter

$count

$top

$skip

$skipToken

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

DEMOMetadaten einsehen

und verstehen

Aktionen ausführen

• Metadaten enthalten auch Actions

– Dateien erstellen, löschen, verschieben, ...

– Excel-Dateien navigieren, aktualisieren, speichern,...

– Mails erstellen, versenden, beantworten, ...

DEMOEine 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

Funktioniert für Geschäfts-/Schulkonto, nicht für persönliches Konto

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

http://dev.office.com/app-registration

V2.0: http://apps.dev.microsoft.com

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

• JSON Web Token (JWT) anschauen:

http://calebb.net/

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

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 | [email protected]

– www.thomasclaudiushuber.com

• Session-Inhalt: www.thomasclaudiushuber.com/talks

• Office 365 Demo-Umgebung anlegen:

- http://demos.microsoft.com

- Graph Samples: http://github.com/microsoftgraph