You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to configure my Django REST Framework app to use django-auth-adfs for Microsoft Entra ID (former Azure AD B2C), but I have an error with signature verification.
with a few additions to make it work with Microsoft Entra:
importosfrompprintimportpprintimportrequestsfromdotenvimportload_dotenv# Load environment variables from .env fileload_dotenv()
# User credentialsuser=os.getenv('USER_EMAIL')
password=os.getenv('USER_PASSWORD')
# OAuth 2.0 token endpointtenant_id=os.getenv('AAD_B2C_TENANT_ID')
token_url=f"https://login.microsoftonline.com/{tenant_id}/oauth2/token"# Client (application) ID and secretclient_id=os.getenv('AAD_B2C_CLIENT_ID')
client_secret=os.getenv('AAD_B2C_CLIENT_SECRET')
# API scopeapi_scope=f"User.Read api://{client_id}/Backend.Read"# Prepare the payloadpayload= {
"grant_type": "password",
"response_type": "token",
"client_id": client_id,
"client_secret": client_secret,
"username": user,
"password": password,
"resource": client_id,
"scope": f"openid profile email {api_scope}",
}
# Request an access tokenresponse=requests.post(
token_url,
data=payload,
verify=True# Ensure SSL certificates are verified
)
# Check for errorstry:
response.raise_for_status()
response_data=response.json()
access_token=response_data['access_token']
print('Access token retrieved successfully.')
exceptrequests.exceptions.HTTPErroraserr:
print('Error retrieving access token:')
print(response.text)
raiseSystemExit(err)
# Make a request to the APIheaders= {
'Accept': 'application/json',
'Authorization': f'Bearer {access_token}',
}
api_response=requests.get(
'http://localhost:8000/api/contract',
headers=headers,
verify=True
)
# Check for errorstry:
api_response.raise_for_status()
# Print the API responsepprint(api_response.json())
exceptrequests.exceptions.HTTPErroraserr:
print('API request failed:')
print(api_response.text)
raiseSystemExit(err)
And the auth works in this case, I successfully getting the access_token and using it to call my app endpoint http://localhost:8000/api/contract.
However, when i'm trying to authorize within my api in the Chrome browser via oauth2/login, I keep getting [django_auth_adfs:157] Error decoding signature: Signature verification failed error.
"""
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('api.urls')),
path('oauth2/', include('django_auth_adfs.urls')),
]
I also tried to change urls to path('oauth2/', include('django_auth_adfs.drf_urls')),as suggested in the docs. But it cause a backend error django.urls.exceptions.NoReverseMatch: 'django_auth_adfs' is not a registered namespace`.
Upvote & Fund
We're using Polar.sh so you can upvote and help fund this issue.
We receive the funding once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog.
The text was updated successfully, but these errors were encountered:
There may be another call you need to make. The goal here isn't to avoid the error by disabling the checks, but to understand what is being sent so you can make changes to get things to work appropriately.
I've been trying to configure my Django REST Framework app to use django-auth-adfs for Microsoft Entra ID (former Azure AD B2C), but I have an error with signature verification.
Prior to test oauth2/login page, I tried the example listed in this page
https://django-auth-adfs.readthedocs.io/en/latest/rest_framework.html
with a few additions to make it work with Microsoft Entra:
And the auth works in this case, I successfully getting the
access_token
and using it to call my app endpointhttp://localhost:8000/api/contract
.However, when i'm trying to authorize within my api in the Chrome browser via
oauth2/login
, I keep getting[django_auth_adfs:157] Error decoding signature: Signature verification failed
error.Here is ADFS config in my DRF app settings.py
urls.py
I also tried to change urls to path('oauth2/', include('django_auth_adfs.drf_urls')),
as suggested in the docs. But it cause a backend error
django.urls.exceptions.NoReverseMatch: 'django_auth_adfs' is not a registered namespace`.Upvote & Fund
The text was updated successfully, but these errors were encountered: