Skip to content

Commit 8e87b71

Browse files
committed
Added CHANGES.md to reflect 2.1 version (changed from 3.0)
Added `account.get_authenticated_usernames`
1 parent 8c255f0 commit 8e87b71

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

CHANGES.md

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
Almost every release features a lot of bugfixes but those are not listed here.
44

5+
## Version 2.1.0 (2025-02-13)
6+
7+
[!IMPORTANT]
8+
> Removed custom authentication in favour of msal. Old tokens will not work with this version and will require a new authentication flow.
9+
10+
- Account: you can now work with multiple users by changing `account.username` when using auth flow type authorization.
11+
- Connection methods `get_authorization_url` and `request_token` are now present in the `Account`object. You will no longer need to use the ones from the `Connection` object unless doing something fancy.
12+
- Account and Connection: the authentication flow has changed and now returns different objects (`get_authorization_url` and `request_token`).
13+
- TokenBackend: they now inherit from the msal cache system. You can now remove tokens, get access scopes from tokens, add a cryptography manager to encrypt and decrypt and much more.
14+
- Scopes are now longer stored into the connection. Scopes are only needed when authenticating and will be stored inside the token data on the token backend.
15+
516
## Version 2.0.38 (2024-11-19)
617
- Added 'on_premises_sam_account_name' to directory.py (Thanks @danpoltawski)
718
- TokenBackend: Added DjangoTokenBackend (Thanks @sdelgadoc)

O365/account.py

+10
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ def username(self) -> Optional[str]:
180180
""" Returns the username in use for the account"""
181181
return self.con.username
182182

183+
def get_authenticated_usernames(self) -> list[str]:
184+
""" Returns a list of usernames that are authenticated and have a valid access or refresh token. """
185+
usernames = []
186+
for account in self.con.token_backend.get_all_accounts():
187+
username = account.get('username')
188+
if username and not self.con.token_backend.token_is_expired(username=username, refresh_token=True):
189+
usernames.append(username)
190+
191+
return usernames
192+
183193
@username.setter
184194
def username(self, username: Optional[str]) -> None:
185195
"""

O365/utils/token.py

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def _get_home_account_id(self, username: str) -> Optional[str]:
9292
log.debug(f'No account found for username: {username}')
9393
return None
9494

95+
def get_all_accounts(self) -> list[dict]:
96+
""" Returns a list of all accounts present in the token cache"""
97+
return list(self.search(TokenCache.CredentialType.ACCOUNT))
98+
9599
def get_account(self, *, username: Optional[str] = None, home_account_id: Optional[str] = None) -> Optional[dict]:
96100
""" Gets the account object for the specified username or home_account_id """
97101
if username and home_account_id:

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
> Detailed usage documentation is [still in progress](https://o365.github.io/python-o365/latest/index.html)
1010
11+
> [!IMPORTANT]
12+
> With version 2.1 old access tokens will not work and the library will require a new authentication flow to get new access and refresh tokens.
13+
1114
This project aims to make interacting with Microsoft Graph and Office 365 easy to do in a Pythonic way.
1215
Access to Email, Calendar, Contacts, OneDrive, etc. Are easy to do in a way that feel easy and straight forward to beginners and feels just right to seasoned python programmer.
1316

@@ -128,7 +131,7 @@ if not account.is_authenticated: # will check if there is a token and has not e
128131
You can only authenticate using oauth authentication because Microsoft deprecated basic auth on November 1st 2018.
129132

130133
> [!IMPORTANT]
131-
> Until version 3.0 this library was using a custom authentication mechanism. On 3.0 we moved to using **[msal](https://learn.microsoft.com/es-es/entra/identity-platform/msal-overview)** to achieve the authentication.
134+
> Until version 2.1 this library was using a custom authentication mechanism. On 2.1 we moved to using **[msal](https://learn.microsoft.com/es-es/entra/identity-platform/msal-overview)** to achieve the authentication.
132135
133136
There are currently three authentication methods:
134137

@@ -567,7 +570,7 @@ account.username = '[email protected]'
567570
account.username = '[email protected]'
568571
# now every call will use the auth of the user2
569572
```
570-
> This is only possible in version 3.0. Before 3.0 you had to instantiate one Account for each user.
573+
> This is only possible in version 2.1. Before 2.1 you had to instantiate one Account for each user.
571574
572575
## Protocols
573576
Protocols handles the aspects of communications between different APIs.

0 commit comments

Comments
 (0)