Esempio n. 1
0
        public BuiltInAuthProvider(string[] scopes, ILogger logger, BuiltInAuthConfig config)
        {
            if (config?.IsEnabled != true)
            {
                throw new InvalidOperationException("Built-in authentication is not configured (i.e. Function or App Service is not linked with an app registration)");
            }

            _scopes = scopes;
            _logger = logger;

            _msalClient = ConfidentialClientApplicationBuilder
                          .Create(config.ClientId)
                          .WithAuthority(AadAuthorityAudience.AzureAdMyOrg, true)
                          .WithTenantId(config.TenantId)
                          .WithClientSecret(config.ClientSecret)
                          .Build();
        }
Esempio n. 2
0
        public GraphApiService(ILoggerFactory loggerFactory, IConfiguration configuration)
        {
            _logger        = loggerFactory.CreateLogger <GraphApiService>();
            _configuration = configuration;
            _authConfig    = new BuiltInAuthConfig(configuration);

            _graphServiceClient = new Lazy <GraphServiceClient>(() =>
            {
                // Create a client credentials auth provider
                var authProvider = new BuiltInAuthProvider(
                    new[] { Constants.AuthScopes.Graph },
                    _logger,
                    _authConfig);

                return(new GraphServiceClient(authProvider));
            });
        }