https://github.com/microsoftgraph/msgraph-dotnet-interactive-extension
An extension for .NET Interactive Notebooks that provides authenticated Microsoft Graph clients.
https://github.com/microsoftgraph/msgraph-dotnet-interactive-extension
devxsample
Last synced: 7 months ago
JSON representation
An extension for .NET Interactive Notebooks that provides authenticated Microsoft Graph clients.
- Host: GitHub
- URL: https://github.com/microsoftgraph/msgraph-dotnet-interactive-extension
- Owner: microsoftgraph
- License: mit
- Created: 2022-09-23T14:25:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-21T13:01:22.000Z (9 months ago)
- Last Synced: 2025-06-09T11:12:46.104Z (8 months ago)
- Topics: devxsample
- Language: C#
- Size: 234 KB
- Stars: 17
- Watchers: 5
- Forks: 6
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Microsoft Graph extension for .NET Interactive Notebooks
[](https://github.com/microsoftgraph/msgraph-dotnet-interactive-extension/actions/workflows/dotnet.yml) 
Sample implementation of Microsoft Graph magic command / extension for [.Net Interactive](https://github.com/dotnet/interactive).
## Test notebook
### Build and import
The below commands can be used to build as a NuGet package (C#), import, and call via magic command.
```bash
rm ~/.nuget/packages/Microsoft.DotNet.Interactive.MicrosoftGraph -Force -Recurse -ErrorAction Ignore
dotnet build ./src/Microsoft.DotNet.Interactive.MicrosoftGraph.csproj
```
```csharp
#i nuget:\src\bin\Debug\
#r "nuget:Microsoft.DotNet.Interactive.MicrosoftGraph,*-*"
```
### Test extension
Display help for "microsoftgraph" magic command
```csharp
#!microsoftgraph -h
```
Instantiate new connections to Microsoft Graph (using each authentication flow), specify unique scope name for parallel use
```csharp
#!microsoftgraph --authentication-flow InteractiveBrowser --scope-name gcInteractiveBrowser --tenant-id --client-id
#!microsoftgraph --authentication-flow DeviceCode --scope-name gcDeviceCode --tenant-id --client-id
#!microsoftgraph --authentication-flow ClientCredential --scope-name gcClientCredential --tenant-id --client-id --client-secret
```
#### Settings file
As an alternative to passing client ID, client secret, and tenant ID as parameters to the magic command, you can put any or all of them into a JSON file and pass the path to that file in the `--config-file` parameter. Values passed in explicit parameters will override values in the JSON file.
```csharp
#!microsoftgraph --authentication-flow ClientCredential --scope-name gcClientCredential ---configFile "./settings.json"
```
##### File schema
```json
{
"clientId": "YOUR_CLIENT_ID",
"clientSecret": "YOUR_CLIENT_SECRET",
"tenantId": "YOUR_TENANT_ID"
}
```
### Interactive Browser sample snippet
```csharp
var me = await gcInteractiveBrowser.Me.Request().GetAsync();
Console.WriteLine($"Me: {me.DisplayName}, {me.UserPrincipalName}");
```
### Device Code sample snippet
```csharp
var users = await gcDeviceCode.Users.Request()
.Top(5)
.Select(u => new {u.DisplayName, u.UserPrincipalName})
.GetAsync();
users.Select(u => new {u.DisplayName, u.UserPrincipalName})
```
### Client Credential sample snippet
```csharp
var queryOptions = new List()
{
new QueryOption("$count", "true")
};
var applications = await gcClientCredential.Applications
.Request( queryOptions )
.Header("ConsistencyLevel","eventual")
.Top(5)
.Select(a => new {a.AppId, a.DisplayName})
.GetAsync();
applications.Select(a => new {a.AppId, a.DisplayName})
```
## Code of conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.