{"id":15410718,"url":"https://github.com/damienbod/aspnetcoremicrosoftgraph","last_synced_at":"2025-04-19T04:15:24.787Z","repository":{"id":44727769,"uuid":"312202096","full_name":"damienbod/AspNetCoreMicrosoftGraph","owner":"damienbod","description":"ASP.NET Core application and API using  Microsoft Graph delegated clients","archived":false,"fork":false,"pushed_at":"2023-12-02T11:03:25.000Z","size":805,"stargazers_count":23,"open_issues_count":3,"forks_count":10,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T06:51:16.303Z","etag":null,"topics":["azure","graph","graph-api","identity","microsoft-identity-platform","oauth2","oidc"],"latest_commit_sha":null,"homepage":"https://damienbod.com/2020/11/20/using-microsoft-graph-api-in-asp-net-core/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/damienbod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-11-12T07:39:59.000Z","updated_at":"2024-07-29T02:47:37.000Z","dependencies_parsed_at":"2023-11-22T13:41:23.274Z","dependency_job_id":"270fff6f-4e6b-4452-a49c-3c0c697eca68","html_url":"https://github.com/damienbod/AspNetCoreMicrosoftGraph","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damienbod%2FAspNetCoreMicrosoftGraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damienbod%2FAspNetCoreMicrosoftGraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damienbod%2FAspNetCoreMicrosoftGraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damienbod%2FAspNetCoreMicrosoftGraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/damienbod","download_url":"https://codeload.github.com/damienbod/AspNetCoreMicrosoftGraph/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249191314,"owners_count":21227543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure","graph","graph-api","identity","microsoft-identity-platform","oauth2","oidc"],"created_at":"2024-10-01T16:46:00.257Z","updated_at":"2025-04-19T04:15:24.768Z","avatar_url":"https://github.com/damienbod.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![.NET](https://github.com/damienbod/AspNetCoreMicrosoftGraph/actions/workflows/dotnet.yml/badge.svg)](https://github.com/damienbod/AspNetCoreMicrosoftGraph/actions/workflows/dotnet.yml)\r\n\r\n# Using Microsoft Graph API delegated clients in ASP.NET Core\r\n\r\nhttps://damienbod.com/2020/11/20/using-microsoft-graph-api-in-asp-net-core/\r\n\r\n## Delegated API permissions\r\n\r\nSites.Read.All \r\n\r\n## Graph API setup in Web API project\r\n\r\n```csharp\r\nbuilder.Services.AddScoped\u003cGraphApiClientDirect\u003e();\r\n\r\nbuilder.Services.AddMicrosoftIdentityWebApiAuthentication(builder.Configuration)\r\n    .EnableTokenAcquisitionToCallDownstreamApi()\r\n    .AddMicrosoftGraph()\r\n    .AddInMemoryTokenCaches();\r\n```\r\n\r\nappsettings.json\r\n\r\n```json\r\n  \"AzureAd\": {\r\n    \"Instance\": \"https://login.microsoftonline.com/\",\r\n    \"Domain\": \"damienbodsharepoint.onmicrosoft.com\",\r\n    \"CallbackPath\": \"/signin-oidc\",\r\n    \"ClientId\": \"89cbcff9-7c4e-4659-9948-d6f7fda186e1\", // sharepoint graph api\r\n    \"TenantId\": \"5698af84-5720-4ff0-bdc3-9d9195314244\"\r\n    // Secret is required for the downstream Graph API call\r\n    // secret is not required for the API itself\r\n    //\"ClientSecret\": \"--secret-in-user-secrets--\"\r\n  },\r\n ```\r\n\r\nGraph service from API for OBO flow, downstream API\r\n\r\n ```csharp\r\nprivate readonly GraphServiceClient _graphServiceClient;\r\n\r\n// \"user.read Sites.Read.All\" consented in the App registration\r\n// The default scope is used because this is a downstream API OBO delegated user flow\r\nprivate const string SCOPES = \"https://graph.microsoft.com/.default\";\r\n\r\npublic GraphApiClientDirect(GraphServiceClient graphServiceClient)\r\n{\r\n    // https://graph.microsoft.com/.default\r\n    // \"user.read Sites.Read.All\" consented in the App registration\r\n    _graphServiceClient = graphServiceClient;\r\n}\r\n ```\r\n\r\n## History\r\n\r\n- 2023-12-02 Fix photo streaming\r\n- 2023-11-22 Updated .NET 8\r\n- 2023-08-26 Improved code, added comments\r\n- 2023-08-22 Updated to Graph 5 \r\n- 2023-08-22 Updated packages and startup\r\n- 2023-03-02 Updated packages\r\n- 2023-01-15 Updated packages to .NET 7\r\n- 2022-06-10 Updated packages\r\n- 2022-01-28 Updated packages\r\n- 2021-12-15 Updated packages\r\n- 2021-10-29 Updated to .NET 6, Microsoft.Identity.Web 1.18.0\r\n- 2021-02-28 Updated to Microsoft.Identity.Web 1.7.0\r\n- 2021-02-13 Updated to Microsoft.Identity.Web 1.6.0\r\n\r\n## Links\r\n\r\nhttps://developer.microsoft.com/en-us/graph/\r\n\r\nhttps://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests\r\n\r\nhttps://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamienbod%2Faspnetcoremicrosoftgraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdamienbod%2Faspnetcoremicrosoftgraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamienbod%2Faspnetcoremicrosoftgraph/lists"}