Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports dSTS by ClientApplication(..., authority="https://...example.com/dstsv2/...") #772

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

rayluo
Copy link
Collaborator

@rayluo rayluo commented Dec 7, 2024

Feature request #767 calls for support for dSTS authority.

The understanding was that:

  • (a) The dSTS authority behaves similarly to an oidc_authority (i.e. no Instance Discovery, no "/v2.0" hardcoded string within its endpoint), so, it should just work if the caller would choose to put a dSTS url into the oidc_authority parameter, even if we might not advertise so.
  • (b) Yet, we choose to allow using dSTS in the "traditional way", by accepting it via the authority parameter, so that MSAL's downstream ecosystem can support dSTS transparently without needing to pick up the oidc_authority parameter first.

Therefore, this PR attempts an implementation that simply converts the authority=https://foo.bar.example.com/dstsv2/placeholder into oidc_authority=https://foo.bar.example.com/dstsv2/placeholder under the hood, and then all the oidc authority behaviors will automatically kick in.

With regard to the tests:

  • The test cases were refactored so that the new DstsAuthorityTestCase inherits all the previous OidcAuthorityTestCase (therefore testing point A above).
  • A new test case was added to test the new behavior of authority=https://foo.bar.example.com/dstsv2/placeholder (therefore testing point B above)
  • Currently, there is no new test cases mapping to the Acceptance Tests described in this request, because this PR builds up on top of the previously tested features (OIDC authority) and does not introduce new code in the token acquisition code path. In particular, #2 doesn't apply because MSAL Python does not support WithTenant(...). But I'm open to add more test cases if desirable.

This will resolve #767

P.S.: The test automation is currently failing due to other reason. They will be fixed soon outside of this PR. This situation does not prevent this PR from being reviewed. Test automation works again now.

@rayluo rayluo requested a review from a team as a code owner December 7, 2024 07:55
@rayluo rayluo changed the title Adds dSTS authority (as if it were an oidc_authority) Supports dSTS by ClientApplication(..., authority="https://...example.com/dstsv2/...") Dec 7, 2024
@@ -623,6 +624,9 @@ def __init__(
# Here the self.authority will not be the same type as authority in input
if oidc_authority and authority:
raise ValueError("You can not provide both authority and oidc_authority")
if isinstance(authority, str) and urlparse(authority).path.startswith(
"/dstsv2"): # dSTS authority's path always starts with "/dstsv2"
oidc_authority = authority # So we treat it as if an oidc_authority
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

I am wondering though how does MSAL Py handle changing the tenant at the request level? I am asking because Azure SDK does this and Azure SDK wants to remain agnostic of authority type (i.e. they want MSAL to just work with AAD, ADFS, dSTS)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simplest is to have request.WithTenantId(tid) do nothing in case the authority is dSTS.

Needs a unit test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MSAL Python does not currently support request.WithTenant(...) at all. Confirmed with a downstream partner that they are not currently using it either. It was tracked as a feature request, which we can work on.

Do we want to proceed with this PR as-is, or mark it as blocked while we pick up the WithTenant(...) feature now?

class DstsAuthorityTestCase(OidcAuthorityTestCase):
# Inherits OidcAuthority's test cases and run them with a dSTS authority
authority = ( # dSTS is single tenanted with a dummy tenant placeholder
'https://test-instance1-dsts.dsts.core.azure-test.net/dstsv2/tid')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add a test case with common? I think with dsts there can be a tenant id or common used in the authority.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure how common is "common" :) and user discovery in dsts. It may be worth asking Sai before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure how common is "common" :) and user discovery in dsts. It may be worth asking Sai before.

You meant OIDC discovery? This is the OIDC discovery for common and this is for the non-common. I'll get back to you when I hear back from Sai.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, "common" is supported but doesn't have the same meaning and eSTS "common", since dSTS is single tenanted. So to me it doesn't make sense to inherit all of eSTS complex logic around multi-tenancy, such as replacing "common" with the id token's tid in the cache etc.

A test is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You meant OIDC discovery? This is the OIDC discovery for common and this is for the non-common. I'll get back to you when I hear back from Sai.

Confirmed with Sai that the seemingly two sets of authorities, common and un-common, are just a side effect of reusing some eSTS code. Under the hood, that common endpoint will still convert the "common" into the tenant id and mint a token for that tenant id.

So to me it doesn't make sense to inherit all of eSTS complex logic around multi-tenancy, such as replacing "common" with the id token's tid in the cache etc.

MSAL Python's tenant agnostic approach does not attempt converting "common" into tid.

Copy link

@neha-bhargava neha-bhargava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve with comment to add another test for common as tenant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] dSTS support
3 participants