public async Task <ClientContext> GetSPClientContext(string username, string password, string clientId)
        {
            var accessToken = await _tokenCacheService.TryGetValue(username, password, TokenType.SharePoint, clientId);

            var spAdminUrl = $"https://{username.Substring(username.IndexOf("@") + 1, username.IndexOf(".") - username.IndexOf("@") - 1)}-admin.sharepoint.com/";
            var context    = new ClientContext(new Uri(spAdminUrl));

            context.ExecutingWebRequest += (sender, e) =>
            {
                e.WebRequestExecutor.RequestHeaders["Authorization"] = "Bearer " + accessToken;
            };
            return(context);
        }
Ejemplo n.º 2
0
        public async Task <GraphServiceClient> GetGraphServiceClientByIdentity(string username, string password)
        {
            var accessToken = await _tokenCacheService.TryGetValue(username, password, TokenType.AzureAD);

            var graphClient = new GraphServiceClient(new DelegateAuthenticationProvider(async(request) => {
                request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
                await Task.FromResult(true);
            }));

            return(graphClient);
        }
        public async Task <HttpClient> GetHttpClient(string username, string password, TokenType tokenType, string clientId = "")
        {
            var accessToken = await _tokenCacheService.TryGetValue(username, password, tokenType, clientId);

            return(BuildHttpClient(accessToken));
        }