Skip to content

Commit 712e16d

Browse files
committed
Introduced filestorage & partners namespaces, fixes for revoke_delegated_permissions method
1 parent 39644e6 commit 712e16d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+503
-68
lines changed

examples/auth/__init__.py

Whitespace-only changes.

examples/auth/delegated.txt

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
AdministrativeUnit.ReadWrite.All
2+
Application.Read.All
3+
Application.ReadWrite.All
4+
AuditLog.Read.All
5+
BackupRestore-Control.Read.All
6+
Bookings.Manage.All
7+
Calendars.ReadWrite.Shared
8+
ChannelMember.ReadWrite.All
9+
ChannelMessage.ReadWrite
10+
Chat.ReadWrite
11+
Chat.ReadWrite.All
12+
DeviceLocalCredential.Read.All
13+
DeviceManagementConfiguration.Read.All
14+
DeviceManagementManagedDevices.ReadWrite.All
15+
Directory.AccessAsUser.All
16+
Directory.ReadWrite.All
17+
Domain.ReadWrite.All
18+
Files.Read.All
19+
Files.ReadWrite.All
20+
Group.Read.All
21+
Group.ReadWrite.All
22+
Mail.ReadWrite
23+
MailboxSettings.ReadWrite
24+
Notes.Create
25+
Notes.ReadWrite.All
26+
OnlineMeetings.ReadWrite
27+
Presence.Read.All
28+
Presence.ReadWrite
29+
Reports.Read.All
30+
ServiceHealth.Read.All
31+
SharePointTenantSettings.ReadWrite.All
32+
Sites.Manage.All
33+
Sites.ReadWrite.All
34+
Tasks.ReadWrite
35+
Tasks.ReadWrite.Shared
36+
Team.ReadBasic.All
37+
TeamMember.ReadWrite.All
38+
ThreatAssessment.ReadWrite.All
39+
User.ReadWrite.All
40+
UserActivity.ReadWrite.CreatedByApp
41+
UserAuthenticationMethod.Read.All
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Demonstrates how to login when the user may be prompted for input by the authorization server.
3+
For example, to sign in, perform multi-factor authentication (MFA), or to grant consent
4+
to more resource access permissions.
5+
6+
Prerequisite: In Azure Portal, configure the Redirect URI of your
7+
"Mobile and Desktop application" as ``http://localhost``.
8+
9+
https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#interactive-and-non-interactive-authentication
10+
"""
11+
12+
from office365.sharepoint.client_context import ClientContext
13+
from tests import test_client_id, test_site_url, test_tenant
14+
15+
ctx = ClientContext(test_site_url).with_interactive(test_tenant, test_client_id)
16+
me = ctx.web.current_user.get().execute_query()
17+
web = ctx.web.get().execute_query()
18+
print(me.login_name)
19+
print(web.title)

examples/auth/register_sharepoint_apponly.py renamed to examples/auth/sharepoint/register_apponly.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
openssl req -x509 -newkey rsa:2048 -keyout selfsignkey.pem -out selfsigncert.pem -nodes -days 365
1010
1111
2. register Azure AD application
12-
3. add permissions
13-
4. upload certificate (public key)
12+
3. assign permissions (for instance Sites.FullControl.All permission)
13+
4. grant Admin Consent.
14+
4. create and upload certificate (public key).
15+
5. assign App-Only Role to SharePoint.
1416
1517
"""
1618

examples/directory/applications/grant_delegated_perms.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222

2323
resource = client.service_principals.get_by_name("Microsoft Graph")
24-
# app_role = "User.Read.All"
25-
app_role = "DeviceLocalCredential.Read.All"
24+
app_role = "FileStorageContainer.Selected"
2625
user = client.users.get_by_principal_name(test_user_principal_name)
2726
resource.grant_delegated_permissions(test_client_id, user, app_role).execute_query()

examples/directory/applications/has_delegated_perms.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
)
1818

1919
resource = client.service_principals.get_by_name("Microsoft Graph")
20-
scope = "DeviceLocalCredential.Read.All"
20+
scope = "FileStorageContainer.Selected"
2121
user = client.users.get_by_principal_name(test_admin_principal_name)
2222
client_app = client.applications.get_by_app_id(test_client_id)
23-
# result = resource.get_delegated_permissions(test_client_id, user).execute_query()
2423
result = resource.get_delegated_permissions(test_client_id).execute_query()
2524
if len([cur_scope for cur_scope in result.value if cur_scope == scope]) == 0:
2625
print("Delegated permission '{0}' is not granted".format(scope))
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Disable MFA
3+
"""
4+
5+
from office365.graph_client import GraphClient
6+
from tests import test_client_id, test_password, test_tenant, test_username
7+
8+
client = GraphClient(tenant=test_tenant).with_username_and_password(
9+
test_client_id, test_username, test_password
10+
)
11+
12+
resource = client.service_principals.get_by_name("Microsoft Graph")
13+
14+
# resource.revoke_delegated_permissions(test_client_id).execute_query()
15+
16+
resource.grant_delegated_permissions(
17+
test_client_id, None, "UserAuthenticationMethod.ReadWrite"
18+
).execute_query()
19+
20+
methods = client.me.authentication.microsoft_authenticator_methods.get().execute_query()
21+
for method in methods:
22+
method.delete_object().execute_query()

generator/import_metadata.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def export_to_file(path, content):
2626
"--endpoint",
2727
dest="endpoint",
2828
help="Import metadata endpoint",
29-
default="graph",
29+
default="sharepoint",
3030
)
3131
parser.add_argument(
3232
"-p",
3333
"--path",
3434
dest="path",
35-
default="./metadata/Graph.xml",
35+
default="./metadata/SharePoint.xml",
3636
help="Import metadata endpoint",
3737
)
3838

generator/metadata/Graph.xml

+16
Original file line numberDiff line numberDiff line change
@@ -20466,6 +20466,11 @@ within the time frame of their original request."/>
2046620466
<Member Name="selfRenew" Value="9"/>
2046720467
<Member Name="unknownFutureValue" Value="10"/>
2046820468
</EnumType>
20469+
<EnumType Name="incompatiblePrinterSettings">
20470+
<Member Name="show" Value="0"/>
20471+
<Member Name="hide" Value="1"/>
20472+
<Member Name="unknownFutureValue" Value="2"/>
20473+
</EnumType>
2046920474
<EnumType Name="printColorMode">
2047020475
<Member Name="blackAndWhite" Value="0"/>
2047120476
<Member Name="grayscale" Value="1"/>
@@ -33115,6 +33120,9 @@ within the time frame of their original request."/>
3311533120
<Property Name="notificationType" Type="Edm.String"/>
3311633121
<Property Name="recipientType" Type="Edm.String"/>
3311733122
</EntityType>
33123+
<ComplexType Name="airPrintSettings">
33124+
<Property Name="incompatiblePrinters" Type="graph.incompatiblePrinterSettings" Nullable="false"/>
33125+
</ComplexType>
3311833126
<ComplexType Name="archivedPrintJob">
3311933127
<Property Name="acquiredByPrinter" Type="Edm.Boolean" Nullable="false"/>
3312033128
<Property Name="acquiredDateTime" Type="Edm.DateTimeOffset"/>
@@ -33186,6 +33194,9 @@ within the time frame of their original request."/>
3318633194
<Property Name="quality" Type="graph.printQuality"/>
3318733195
<Property Name="scaling" Type="graph.printScaling"/>
3318833196
</ComplexType>
33197+
<ComplexType Name="printerDiscoverySettings">
33198+
<Property Name="airPrint" Type="graph.airPrintSettings" Nullable="false"/>
33199+
</ComplexType>
3318933200
<ComplexType Name="printerLocation">
3319033201
<Property Name="altitudeInMeters" Type="Edm.Int32"/>
3319133202
<Property Name="building" Type="Edm.String"/>
@@ -33252,6 +33263,7 @@ within the time frame of their original request."/>
3325233263
</ComplexType>
3325333264
<ComplexType Name="printSettings">
3325433265
<Property Name="documentConversionEnabled" Type="Edm.Boolean" Nullable="false"/>
33266+
<Property Name="printerDiscoverySettings" Type="graph.printerDiscoverySettings"/>
3325533267
</ComplexType>
3325633268
<ComplexType Name="printTaskStatus">
3325733269
<Property Name="description" Type="Edm.String" Nullable="false"/>
@@ -33317,16 +33329,20 @@ within the time frame of their original request."/>
3331733329
<EntityType Name="printDocument" BaseType="graph.entity" HasStream="true">
3331833330
<Property Name="contentType" Type="Edm.String"/>
3331933331
<Property Name="displayName" Type="Edm.String"/>
33332+
<Property Name="downloadedDateTime" Type="Edm.DateTimeOffset"/>
3332033333
<Property Name="size" Type="Edm.Int64" Nullable="false"/>
33334+
<Property Name="uploadedDateTime" Type="Edm.DateTimeOffset"/>
3332133335
</EntityType>
3332233336
<EntityType Name="printTaskTrigger" BaseType="graph.entity">
3332333337
<Property Name="event" Type="graph.printEvent" Nullable="false"/>
3332433338
<NavigationProperty Name="definition" Type="graph.printTaskDefinition" Nullable="false"/>
3332533339
</EntityType>
3332633340
<EntityType Name="printJob" BaseType="graph.entity">
33341+
<Property Name="acknowledgedDateTime" Type="Edm.DateTimeOffset"/>
3332733342
<Property Name="configuration" Type="graph.printJobConfiguration" Nullable="false"/>
3332833343
<Property Name="createdBy" Type="graph.userIdentity"/>
3332933344
<Property Name="createdDateTime" Type="Edm.DateTimeOffset" Nullable="false"/>
33345+
<Property Name="errorCode" Type="Edm.Int32"/>
3333033346
<Property Name="isFetchable" Type="Edm.Boolean" Nullable="false"/>
3333133347
<Property Name="redirectedFrom" Type="Edm.String"/>
3333233348
<Property Name="redirectedTo" Type="Edm.String"/>

office365/directory/authentication/authentication.py

+16
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ def fido2_methods(self):
4242
),
4343
)
4444

45+
@property
46+
def microsoft_authenticator_methods(self):
47+
from office365.directory.authentication.methods.microsoft_authenticator import (
48+
MicrosoftAuthenticatorAuthenticationMethod,
49+
)
50+
51+
return self.properties.get(
52+
"microsoftAuthenticatorMethods",
53+
EntityCollection(
54+
self.context,
55+
MicrosoftAuthenticatorAuthenticationMethod,
56+
ResourcePath("microsoftAuthenticatorMethods", self.resource_path),
57+
),
58+
)
59+
4560
@property
4661
def phone_methods(self):
4762
"""The phone numbers registered to a user for authentication."""
@@ -94,6 +109,7 @@ def get_property(self, name, default_value=None):
94109
property_mapping = {
95110
"emailMethods": self.email_methods,
96111
"fido2Methods": self.fido2_methods,
112+
"microsoftAuthenticatorMethods": self.microsoft_authenticator_methods,
97113
"passwordMethods": self.password_methods,
98114
"phoneMethods": self.phone_methods,
99115
}

office365/directory/authentication/method_target.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33

44
class AuthenticationMethodTarget(Entity):
5-
""""""
5+
"""A collection of groups that are enabled to use an authentication method as part of an authentication
6+
method policy in Microsoft Entra ID."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from office365.directory.authentication.methods.method import AuthenticationMethod
2+
3+
4+
class MicrosoftAuthenticatorAuthenticationMethod(AuthenticationMethod):
5+
"""A representation of the Microsoft Authenticator app registered to a user. Microsoft Authenticator
6+
is an authentication method."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from office365.directory.authentication.method_configuration import (
2+
AuthenticationMethodConfiguration,
3+
)
4+
5+
6+
class SmsAuthenticationMethodConfiguration(AuthenticationMethodConfiguration):
7+
"""Represents a text message authentication methods policy. Authentication methods policies define
8+
configuration settings and users or groups that are enabled to use the authentication method.
9+
"""

office365/directory/certificates/self_signed.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,37 @@
44
class SelfSignedCertificate(ClientValue):
55
"""Contains the public part of a signing certificate."""
66

7-
def __init__(self, display_name=None):
7+
def __init__(
8+
self,
9+
custom_key_identifier=None,
10+
display_name=None,
11+
end_datetime=None,
12+
key=None,
13+
key_id=None,
14+
start_datetime=None,
15+
thumbprint=None,
16+
type_=None,
17+
usage=None,
18+
):
819
"""
9-
:param str display_name:
20+
:param custom_key_identifier: Custom key identifier.
21+
:param str display_name: The friendly name for the key.
22+
:param end_datetime: The date and time at which the credential expires. The timestamp type represents date
23+
and time information using ISO 8601 format and is always in UTC time
24+
:param key: The value for the key credential. Should be a Base-64 encoded value.
25+
:param key_id: The unique identifier (GUID) for the key.
26+
:param start_datetime: The date and time at which the credential becomes valid. The timestamp type represents
27+
date and time information using ISO 8601 format and is always in UTC time
28+
:param thumbprint: The thumbprint value for the key.
29+
:param type_: The type of key credential. AsymmetricX509Cert.
30+
:param usage: A string that describes the purpose for which the key can be used. The possible value is Verify.
1031
"""
32+
self.customKeyIdentifier = custom_key_identifier
1133
self.displayName = display_name
34+
self.endDateTime = end_datetime
35+
self.key = key
36+
self.keyId = key_id
37+
self.startDateTime = start_datetime
38+
self.thumbprint = thumbprint
39+
self.type = type_
40+
self.usage = usage

office365/directory/identities/conditional_access_root.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
from office365.directory.policies.conditional_access import ConditionalAccessPolicy
12
from office365.entity import Entity
3+
from office365.entity_collection import EntityCollection
24
from office365.runtime.paths.resource_path import ResourcePath
35

46

@@ -15,3 +17,15 @@ def authentication_strength(self):
1517
self.context, ResourcePath("authenticationStrength", self.resource_path)
1618
),
1719
)
20+
21+
@property
22+
def policies(self):
23+
"""Returns a collection of the specified Conditional Access (CA) policies."""
24+
return self.properties.get(
25+
"policies",
26+
EntityCollection(
27+
self.context,
28+
ConditionalAccessPolicy,
29+
ResourcePath("policies", self.resource_path),
30+
),
31+
)

office365/directory/policies/cross_tenant_access.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def templates(self):
2121
"""Represents the base policy in the directory for multitenant organization settings."""
2222
return self.properties.get(
2323
"templates",
24-
PolicyTemplate(
24+
PolicyTemplate(
2525
self.context,
2626
ResourcePath("templates", self.resource_path),
2727
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from office365.entity import Entity
2+
3+
4+
class FeatureRolloutPolicy(Entity):
5+
"""
6+
Represents a feature rollout policy associated with a directory object. Creating a feature rollout policy
7+
helps tenant administrators to pilot features of Microsoft Entra ID with a specific group before enabling
8+
features for entire organization. This minimizes the impact and helps administrators to test and rollout
9+
authentication related features gradually.
10+
11+
The following are limitations of feature rollout:
12+
13+
- Each feature supports a maximum of 10 groups.
14+
- The appliesTo field only supports groups.
15+
- Dynamic groups and nested groups are not supported.
16+
"""

0 commit comments

Comments
 (0)