Skip to content
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [4.6.2](https://github.com/python-social-auth/social-core/releases/tag/4.6.2) - 2025-06-09

### Changed

- Added Azure OID backend

## [4.6.1](https://github.com/python-social-auth/social-core/releases/tag/4.6.1) - 2025-04-28

### Changed
Expand Down
71 changes: 71 additions & 0 deletions social_core/backends/azuread_oid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from .azuread_tenant import AzureADTenantOAuth2

Check warning on line 1 in social_core/backends/azuread_oid.py

View check run for this annotation

Codecov / codecov/patch

social_core/backends/azuread_oid.py#L1

Added line #L1 was not covered by tests

"""

Check warning on line 3 in social_core/backends/azuread_oid.py

View check run for this annotation

Codecov / codecov/patch

social_core/backends/azuread_oid.py#L3

Added line #L3 was not covered by tests
Copyright (c) 2015 Microsoft Open Technologies, Inc.

All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

"""

Check warning on line 29 in social_core/backends/azuread_oid.py

View check run for this annotation

Codecov / codecov/patch

social_core/backends/azuread_oid.py#L29

Added line #L29 was not covered by tests
Azure AD OAuth2 backend, docs at:
https://python-social-auth.readthedocs.io/en/latest/backends/azuread.html

See https://nicksnettravels.builttoroam.com/post/2017/01/24/Verifying-Azure-Active-Directory-JWT-Tokens.aspx
for verifying JWT tokens.
"""


class AzureADOIDOAuth2(AzureADTenantOAuth2):
name = "azuread-oid-oauth2"

Check warning on line 39 in social_core/backends/azuread_oid.py

View check run for this annotation

Codecov / codecov/patch

social_core/backends/azuread_oid.py#L38-L39

Added lines #L38 - L39 were not covered by tests

def get_user_id(self, details, response):

Check warning on line 41 in social_core/backends/azuread_oid.py

View check run for this annotation

Codecov / codecov/patch

social_core/backends/azuread_oid.py#L41

Added line #L41 was not covered by tests
"""Use account oid as unique id."""
return response.get("oid")

Check warning on line 43 in social_core/backends/azuread_oid.py

View check run for this annotation

Codecov / codecov/patch

social_core/backends/azuread_oid.py#L43

Added line #L43 was not covered by tests


class AzureADV2OIDOAuth2(AzureADOIDOAuth2):
name = "azuread-v2-OID-oauth2"
OPENID_CONFIGURATION_URL = "{base_url}/v2.0/.well-known/openid-configuration{appid}"
AUTHORIZATION_URL = "{base_url}/oauth2/v2.0/authorize"
ACCESS_TOKEN_URL = "{base_url}/oauth2/v2.0/token"
JWKS_URL = "{base_url}/discovery/v2.0/keys{appid}"
DEFAULT_SCOPE = ["openid", "profile", "offline_access"]

Check warning on line 52 in social_core/backends/azuread_oid.py

View check run for this annotation

Codecov / codecov/patch

social_core/backends/azuread_oid.py#L46-L52

Added lines #L46 - L52 were not covered by tests

def get_user_id(self, details, response):

Check warning on line 54 in social_core/backends/azuread_oid.py

View check run for this annotation

Codecov / codecov/patch

social_core/backends/azuread_oid.py#L54

Added line #L54 was not covered by tests
"""Use oid as unique id"""
return response.get("oid")

Check warning on line 56 in social_core/backends/azuread_oid.py

View check run for this annotation

Codecov / codecov/patch

social_core/backends/azuread_oid.py#L56

Added line #L56 was not covered by tests

def get_user_details(self, response):

Check warning on line 58 in social_core/backends/azuread_oid.py

View check run for this annotation

Codecov / codecov/patch

social_core/backends/azuread_oid.py#L58

Added line #L58 was not covered by tests
"""Return user details from Azure AD account"""
fullname, first_name, last_name = (

Check warning on line 60 in social_core/backends/azuread_oid.py

View check run for this annotation

Codecov / codecov/patch

social_core/backends/azuread_oid.py#L60

Added line #L60 was not covered by tests
response.get("name", ""),
response.get("given_name", ""),
response.get("family_name", ""),
)
return {

Check warning on line 65 in social_core/backends/azuread_oid.py

View check run for this annotation

Codecov / codecov/patch

social_core/backends/azuread_oid.py#L65

Added line #L65 was not covered by tests
"username": fullname,
"email": response.get("preferred_username"),
"fullname": fullname,
"first_name": first_name,
"last_name": last_name,
}