Skip to content

Commit

Permalink
feat(microsoft): Configurable endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed May 22, 2024
1 parent dba724d commit 92c1918
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
- When the headless provider signup endpoint was called while that flow was not pending,
a crash would occur. This has been fixed to return a 409 (conflict).

- Microsoft provider: the URLs pointing to the login and graph API are now
configurable via the app settings.


0.63.1 (2024-05-17)
*******************
Expand Down
9 changes: 7 additions & 2 deletions allauth/socialaccount/providers/microsoft/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def _build_tenant_url(self, path):
# Prefer app based tenant setting.
app = get_adapter().get_app(context.request, provider=self.provider_id)
tenant = app.settings.get("tenant", tenant)
return f"https://login.microsoftonline.com/{tenant}{path}"
login_url = app.settings.get("login_url", "https://login.microsoftonline.com")
return f"{login_url}/{tenant}{path}"

@property
def access_token_url(self):
Expand All @@ -49,7 +50,11 @@ def access_token_url(self):
def authorize_url(self):
return self._build_tenant_url("/oauth2/v2.0/authorize")

profile_url = "https://graph.microsoft.com/v1.0/me"
@property
def profile_url(self):
app = get_adapter().get_app(context.request, provider=self.provider_id)
graph_url = app.settings.get("graph_url", "https://graph.microsoft.com")
return f"{graph_url}/v1.0/me"

user_properties = (
"businessPhones",
Expand Down
3 changes: 3 additions & 0 deletions docs/socialaccount/providers/microsoft.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ for the login. To restrict it, change the ``tenant`` setting as shown below.
"secret": "<insert-secret>",
"settings": {
"tenant": "organizations",
# Optional: override URLs (use base URLs without path)
"login_url": "https://login.microsoftonline.com",
"graph_url": "https://graph.microsoft.com",
}
}
]
Expand Down

0 comments on commit 92c1918

Please sign in to comment.