-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathGraphServiceClient.cs
106 lines (96 loc) · 4.87 KB
/
GraphServiceClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------
namespace Microsoft.Graph
{
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Graph.Core.Requests;
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Authentication.Azure;
using Microsoft.Kiota.Abstractions;
using Azure.Core;
/// <summary>
/// A default client implementation.
/// </summary>
public class GraphServiceClient : BaseGraphServiceClient, IBaseClient
{
private static readonly Version assemblyVersion = typeof(GraphServiceClient).GetTypeInfo().Assembly.GetName().Version;
private static readonly GraphClientOptions graphClientOptions = new GraphClientOptions
{
GraphServiceLibraryClientVersion = $"{assemblyVersion.Major}.{assemblyVersion.Minor}.{assemblyVersion.Build}",
GraphServiceTargetVersion = string.Empty,
};
/// <summary>
/// Constructs a new <see cref="GraphServiceClient"/>.
/// </summary>
/// <param name="requestAdapter">The custom <see cref="IRequestAdapter"/> to be used for making requests</param>
/// <param name="baseUrl">The base service URL. For example, "https://graph.microsoft.com/v1.0"</param>
public GraphServiceClient(IRequestAdapter requestAdapter, string baseUrl = null): base(InitializeRequestAdapterWithBaseUrl(requestAdapter,baseUrl))
{
this.RequestAdapter = requestAdapter;
}
/// <summary>
/// Constructs a new <see cref="GraphServiceClient"/>.
/// </summary>
/// <param name="tokenCredential">The <see cref="TokenCredential"/> for authenticating request messages.</param>
/// <param name="scopes">List of scopes for the authentication context.</param>
/// <param name="baseUrl">The base service URL. For example, "https://graph.microsoft.com/v1.0"</param>
public GraphServiceClient(
TokenCredential tokenCredential,
IEnumerable<string> scopes = null,
string baseUrl = null
):this(new Microsoft.Graph.Authentication.AzureIdentityAuthenticationProvider(tokenCredential, null, null,scopes?.ToArray() ?? Array.Empty<string>()), baseUrl)
{
}
/// <summary>
/// Constructs a new <see cref="GraphServiceClient"/>.
/// </summary>
/// <param name="authenticationProvider">The <see cref="IAuthenticationProvider"/> for authenticating request messages.</param>
/// <param name="baseUrl">The base service URL. For example, "https://graph.microsoft.com/v1.0"</param>
public GraphServiceClient(
IAuthenticationProvider authenticationProvider,
string baseUrl = null
): this(new BaseGraphRequestAdapter(authenticationProvider, graphClientOptions),baseUrl)
{
}
/// <summary>
/// Constructs a new <see cref="GraphServiceClient"/>.
/// </summary>
/// <param name="httpClient">The customized <see cref="HttpClient"/> to be used for making requests</param>
/// <param name="authenticationProvider">The <see cref="IAuthenticationProvider"/> for authenticating request messages.
/// Defaults to <see cref="AnonymousAuthenticationProvider"/> so that authentication is handled by custom middleware in the httpClient</param>
/// <param name="baseUrl">The base service URL. For example, "https://graph.microsoft.com/v1.0"</param>
public GraphServiceClient(
HttpClient httpClient,
IAuthenticationProvider authenticationProvider = null,
string baseUrl = null):this(new BaseGraphRequestAdapter(authenticationProvider ?? new AnonymousAuthenticationProvider(), graphClientOptions, httpClient: httpClient),baseUrl)
{
}
/// <summary>
/// Gets the <see cref="IRequestAdapter"/> for sending requests.
/// </summary>
public IRequestAdapter RequestAdapter { get; set; }
/// <summary>
/// Gets the <see cref="BatchRequestBuilder"/> for building batch Requests
/// </summary>
public BatchRequestBuilder Batch
{
get
{
return new BatchRequestBuilder(this.RequestAdapter);
}
}
private static IRequestAdapter InitializeRequestAdapterWithBaseUrl(IRequestAdapter requestAdapter, string baseUrl)
{
if (!string.IsNullOrEmpty(baseUrl))
{
requestAdapter.BaseUrl = baseUrl;
}
return requestAdapter;
}
}
}