Skip to content

Commit b262579

Browse files
author
Alejandro Casanovas
committed
When using the credentials auth_flow_type the tenant_id is now required (googleapis#330 and googleapis#294)
Updated Readme to reflect this change
1 parent 6f9127e commit b262579

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

O365/connection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ def __init__(self, credentials, *, scopes=None,
309309
raise ValueError('Provide valid auth credentials')
310310

311311
self._auth_flow_type = auth_flow_type # 'authorization' or 'credentials'
312+
if auth_flow_type == 'credentials' and tenant_id == 'common':
313+
raise ValueError('When using the "credentials" auth_flow the "tenant_id" must be set')
314+
self.tenant_id = tenant_id
312315
self.auth = credentials
313316
self.scopes = scopes
314317
self.store_token = True

README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,29 @@ You can only authenticate using oauth athentication as Microsoft deprecated basi
117117

118118
There are currently two authentication methods:
119119

120-
- [Authenticate on behalf of a user](https://docs.microsoft.com/en-us/graph/auth-v2-user?context=graph%2Fapi%2F1.0&view=graph-rest-1.0): Any user will give consent to the app to access it's resources.
120+
- [Authenticate on behalf of a user](https://docs.microsoft.com/en-us/graph/auth-v2-user?context=graph%2Fapi%2F1.0&view=graph-rest-1.0):
121+
Any user will give consent to the app to access it's resources.
121122
This oauth flow is called **authorization code grant flow**. This is the default authentication method used by this library.
122-
- [Authenticate with your own identity](https://docs.microsoft.com/en-us/graph/auth-v2-service?context=graph%2Fapi%2F1.0&view=graph-rest-1.0): This will use your own identity. This oauth flow is called **client credentials grant flow**.
123+
- [Authenticate with your own identity](https://docs.microsoft.com/en-us/graph/auth-v2-service?context=graph%2Fapi%2F1.0&view=graph-rest-1.0):
124+
This will use your own identity (the app identity). This oauth flow is called **client credentials grant flow**.
123125

124126
> 'Authenticate with your own identity' is not an allowed method for **Microsoft Personal accounts**.
125127

126128
When to use one or the other and requirements:
127129

128-
Topic | On behalf of a user | With your own identity
129-
:---: | :---: | :---:
130-
**Register the App** | Required | Required
131-
**Requires Admin Consent** | Only on certain advanced permissions | Yes, for everything
132-
**App Permission Type** | Delegated Permissions (on behalf of the user) | Application Permissions
133-
**Auth requirements** | Client Id, Client Secret, Authorization Code | Client Id, Client Secret
134-
**Authentication** | 2 step authentication with user consent | 1 step authentication
135-
**Auth Scopes** | Required | None
136-
**Token Expiration** | 60 Minutes without refresh token or 90 days* | 60 Minutes*
137-
**Resources** | access the user resources, and any shared resources | all Azure AD users
138-
**Microsoft Account Type** | Any | Not Allowed for Personal Accounts
130+
Topic | On behalf of a user *(auth_flow_type=='authorization')* | With your own identity *(auth_flow_type=='credentials')*
131+
:---: | :---: | :---:
132+
**Register the App** | Required | Required
133+
**Requires Admin Consent** | Only on certain advanced permissions | Yes, for everything
134+
**App Permission Type** | Delegated Permissions (on behalf of the user) | Application Permissions
135+
**Auth requirements** | Client Id, Client Secret, Authorization Code | Client Id, Client Secret
136+
**Authentication** | 2 step authentication with user consent | 1 step authentication
137+
**Auth Scopes** | Required | None
138+
**Token Expiration** | 60 Minutes without refresh token or 90 days* | 60 Minutes*
139+
**Login Expiration** | Unlimited if there is a refresh token and as long as a refresh is done within the 90 days | Unlimited
140+
**Resources** | Access the user resources, and any shared resources | All Azure AD users the app has access to
141+
**Microsoft Account Type** | Any | Not Allowed for Personal Accounts
142+
**Tenant ID Required** | Defaults to "common" | Required (can't be "common")
139143

140144
**O365 will automatically refresh the token for you on either authentication method. The refresh token lasts 90 days but it's refreshed on each connection so as long as you connect within 90 days you can have unlimited access.*
141145

@@ -208,7 +212,7 @@ This section is explained using Microsoft Graph Protocol, almost the same applie
208212

209213
- When authenticating with your own identity:
210214

211-
1. Instantiate an `Account` object with the credentials (client id and client secret) and specifying the parameter `auth_flow_type` to *"credentials"*. You don't need to specify any scopes.
215+
1. Instantiate an `Account` object with the credentials (client id and client secret), specifying the parameter `auth_flow_type` to *"credentials"*. You also need to provide a 'tenant_id'. You don't need to specify any scopes.
212216
1. Call `account.authenticate`. This call will request a token for you and store it in the backend. No user interaction is needed. The method will store the token in the backend and return True if the authentication succeeded.
213217

214218
For Example:
@@ -219,7 +223,7 @@ This section is explained using Microsoft Graph Protocol, almost the same applie
219223

220224
# the default protocol will be Microsoft Graph
221225

222-
account = Account(credentials, auth_flow_type='credentials')
226+
account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id')
223227
if account.authenticate():
224228
print('Authenticated!')
225229
```
@@ -531,7 +535,7 @@ message = Message(parent=account, main_resource='shared_mailbox@example.com') #
531535

532536
Usually you will work with the default 'ME' resource, but you can also use one of the following:
533537

534-
- **'me'**: the user which has given consent. the default for every protocol. Overwritten when using "with your own identity" authentication method.
538+
- **'me'**: the user which has given consent. the default for every protocol. Overwritten when using "with your own identity" authentication method (Only available on the authorization auth_flow_type).
535539
- **'user:user@domain.com'**: a shared mailbox or a user account for which you have permissions. If you don't provide 'user:' will be infered anyways.
536540
- **'sharepoint:sharepoint-site-id'**: a sharepoint site id.
537541
- **'group:group-site-id'**: a office365 group id.

0 commit comments

Comments
 (0)