-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Refreshing OnBehalfOf token does not work #21981
Copy link
Copy link
Closed
Labels
Azure.IdentityClientThis issue points to a problem in the data-plane of the library.This issue points to a problem in the data-plane of the library.customer-reportedIssues that are reported by GitHub users external to the Azure organization.Issues that are reported by GitHub users external to the Azure organization.issue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.Workflow: The Azure SDK team believes it to be addressed and ready to close.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as thatThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
Metadata
Metadata
Assignees
Labels
Azure.IdentityClientThis issue points to a problem in the data-plane of the library.This issue points to a problem in the data-plane of the library.customer-reportedIssues that are reported by GitHub users external to the Azure organization.Issues that are reported by GitHub users external to the Azure organization.issue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.Workflow: The Azure SDK team believes it to be addressed and ready to close.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as thatThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
Describe the bug
If the OnBehalfOfCredential from azure.identity.aio is used, the token is not refreshed properly, while OnBehalfOfCredential from azure.identity does refresh the token.
The root cause:
azure.identity.OnBehalfOfCredential uses msal to handle the token, while azure.identity.aio.OnBehalfOfCredential uses an internal AadClient. This AadClient does two things different from msal:
Without the client_secret, the authority server returns:
AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.
I cannot find a reference to this error and the documentation also suggests that it should not be needed for refresh tokens, but the error itself is self-explanatory.
Note that OnBehalfOfCredential swallows this error and continues using the old token. When this token finally expires we get an error that the assertion token has expired (which is correct, but this hides the underlying problem).
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The operation should continue to succeed for a long time (refresh tokens are long-running tokens)
Screenshots
Additional context
Note that if the synchronous variant of OnBehalfOfCredential is used and an object that uses it (e.g. BlobServiceClient), the token is refreshed properly.
By adding the client_secret and extending the scopes of the token (I do not know if the latter is actually needed), the library can be made to work (I tried this with some hack code, but I'm not familiar enough with the code to suggest a proper solution).