Skip to content

Commit c59e3bd

Browse files
authored
Merge pull request #249 from microsoftgraph/fix/update-graph-client-constructor
Update GraphServiceClient constructor params
2 parents 9747611 + 430dd2b commit c59e3bd

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

msgraph/graph_service_client.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,53 @@
1+
from typing import List, Optional, TYPE_CHECKING, Union
2+
from azure.core.credentials import TokenCredential
3+
from azure.core.credentials_async import AsyncTokenCredential
4+
from kiota_authentication_azure.azure_identity_authentication_provider import AzureIdentityAuthenticationProvider
5+
16
from .generated.base_graph_service_client import BaseGraphServiceClient
27
from .graph_request_adapter import GraphRequestAdapter
38

9+
if TYPE_CHECKING:
10+
from .generated.users.item.user_item_request_builder import UserItemRequestBuilder
11+
412
class GraphServiceClient(BaseGraphServiceClient):
5-
def __init__(self, request_adapter: GraphRequestAdapter) -> None:
13+
def __init__(
14+
self,
15+
credentials: Optional[Union[TokenCredential, AsyncTokenCredential]] = None,
16+
scopes: Optional[List[str]] = None,
17+
request_adapter: Optional[GraphRequestAdapter] = None,
18+
) -> None:
19+
"""Constructs a client instance to use for making requests to the
20+
Microsoft Graph beta API.
21+
22+
Args:
23+
credentials (Union[TokenCredential, AsyncTokenCredential]): The
24+
tokenCredential to use for authentication.
25+
scopes (Optional[List[str]]): The scopes to use for authentication.
26+
Defaults to ['https://graph.microsoft.com/.default'].
27+
request_adapter (Optional[GraphRequestAdapter], optional): The request
28+
adapter to use for requests. Defaults to None.
29+
"""
30+
31+
if not request_adapter:
32+
if not credentials:
33+
raise ValueError("Missing request adapter or valid credentials")
34+
if scopes:
35+
auth_provider = AzureIdentityAuthenticationProvider(credentials, scopes=scopes)
36+
else:
37+
auth_provider = AzureIdentityAuthenticationProvider(credentials)
38+
39+
request_adapter = GraphRequestAdapter(auth_provider)
40+
641
super().__init__(request_adapter)
42+
43+
def me(self) -> UserItemRequestBuilder:
44+
"""
45+
Maps requests to /me endpoint to /users/{{user-id}}
46+
"""
47+
from .generated.users.item.user_item_request_builder import UserItemRequestBuilder
48+
49+
url_tpl_parameters = self.path_parameters
50+
url_tpl_parameters["user%2Did"] = "me-token-to-replace"
51+
52+
return UserItemRequestBuilder(self.request_adapter, url_tpl_parameters)
753

0 commit comments

Comments
 (0)