Note – I am feeling blessed by looking response to last article. I got very positive response and got excited for writing next article and dig into more details 😊

Let’s begin the show, in this article and next couple of articles we will discuss one use case and use GRAPH APIs using CSOM to achieve the result. We will explore each and every step in detail.

Use Case: In one of our requirement, our customer want to list out all the Office 365 groups on weekly basis. So that admin can track newly created groups / deleted groups etc. This is very simple use case but will be very good to understand the while concept.

Approach:

We will use GRAPH APIs CSOM SDK.

We will write one simple console application using CSOM SDK which will fetch the Office 365 groups, and will write in one CSV file and email to admin. We will schedule this program weekly basis on any server.

One more option here is rather writing console application we can write Azure web job as well.

Let’s discuss the steps in details.

Choose development
environment – Here in case we are using Visual Studio 2017 + CSOM SDK

Register App in Azure AD

Get APPID and generate
Client Secret key

Configure permission
scope – Give the permission to above created Azure App to use Microsoft Graph
APIs for fetching all Office 365 groups

Install require
packages using NuGet manager

Get Azure Access Token
– To call GRAPH APIs from CSOM, first important thing we require “Azure Access
Token”

In this article we will discuss how to give permissions
to Azure App to use Graph APIs to access the Office 365 groups.
Microsoft Graph allows granular permissions that
control the access to our azure app to resources like Groups, Users etc. Here
our resource is Groups. Our azure app requires permissions to read all groups.

Microsoft Graph has two types of permissions:

Application Permissions

These permissions are used by apps that run without signed-in user present

Example: Apps those run as a background process or jobs

Delegated Permissions – These permissions are used by apps that have a signed-in user present

Following are the steps:

Once we have “Azure App” created we need to give permission to app for Graph APIs as