Last active
February 5, 2021 09:00
-
-
Save SibeeshVenu/821028ee794b70f893c7e3cab379a0fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Graph; | |
using Microsoft.Graph.Auth; | |
using Microsoft.Identity.Client; | |
namespace < YOURNAMESPACE > { | |
public interface IGraphAuthService { | |
GraphServiceClient GetGraphServiceClient(Guid tenantId); | |
} | |
public class GraphAuthService: IGraphAuthService { | |
private readonly IConfiguration _configuration; | |
public GraphAuthService(IConfiguration configuration) { | |
_configuration = configuration; | |
} | |
private ClientCredentialProvider GetGraphAuthProvider(Guid tenantId) { | |
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder | |
.Create(_configuration["AzureAd:ClientId"]) | |
.WithTenantId(Convert.ToString(tenantId)) | |
.WithClientSecret(_configuration["GraphClientSecret"]) | |
.Build(); | |
return new ClientCredentialProvider(confidentialClientApplication); | |
} | |
public GraphServiceClient GetGraphServiceClient(Guid tenantId) = >new GraphServiceClient(GetGraphAuthProvider(tenantId)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment