Rebex Graph

.NET client library for MS Graph API (Exchange Online)

Download 30-day free trial Buy from $199
More .NET libraries

Back to feature list...

Connecting and authenticating

Connecting to Microsoft 365 server 

To connect to the Graph API server at Microsoft 365 (Exchange Online), call the Connect() method:

// create Graph client instance
var client = new Rebex.Net.GraphClient();

// connect to Exchange Online server
client.Connect();

Note: The server name is not needed - graph.microsoft.com is used by default. However, it can be supplied explicitly as well:

// Exchange Online address
var hostname = "graph.microsoft.com";
var port = 443;

// create client object and connect to desired server
var client = new Rebex.Net.GraphClient();
client.Connect(hostname, port);

Authenticating using OAuth access token 

MS Graph uses OAuth 2.0 authentication - to log into the server, the client application needs to obtain an OAuth access token.

The article at How to use OAuth2.0 authentication for Office 365 with Rebex Mail Pack describes the whole process of requesting OAuth access token from Microsoft 365 platform in detail.

// obtain your OAuth access token
// (see https://blog.rebex.net/oauth2-office365-rebex-mail for details)
string token = GetOAuthAccessToken();

// authenticate with the token
client.Login(token);

Back to feature list...