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

B2c implementation #104

Merged
merged 5 commits into from Oct 15, 2019
Merged

B2c implementation #104

merged 5 commits into from Oct 15, 2019

Conversation

rayluo
Copy link
Collaborator

@rayluo rayluo commented Oct 4, 2019

There is an automated test case in this PR to cover username password flow (i.e. ROPC grant), and it passes.

Currently, this implementation is still considered in an early stage. We can use it as a prototype to work on some sample as proof-of-concept, in order to get the whole picture of end-to-end experience of the "new" API surface and calling patterns. The interesting part of this PR, is something NOT in this PR: You will see this PR did NOT touch the source file application.py which contains current public API definition. That means, we keep the high level API surface unchanged for B2C and non-B2C scenarios.

We can install this branch by:

pip install git+https://github.com/AzureAD/microsoft-authentication-library-for-python.git@b2c

We can organize a code walk-through when we officially start the PR code review at a later time.

This PR will eventually resolve #52 .

It will guide app developer to use validate_authority=False when needed.
This would become handy when we meet B2C authority with customized domain.
Copy link

@jmprieur jmprieur left a comment

Choose a reason for hiding this comment

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

LGTM.

Do I understand right that:

  • we avoid doing authority validation when we detect an authority containing b2clogin.com ?
  • for custom domains, the developer would have to turn on authority validation explicitly?

What about detecting that there is an authority with an extra segment (the policy) ?


Answered by Ray inline here, to make the Q&A stay together:

  1. Yes
  2. They need to do that, but they do not have to remember to do so. Our SDK will remind them with a meaningful error message when we detect an Instance Discovery failure. #Supportability
  3. Detecting the extra segment would be unreliable, due to the flexibility of that B2C authority format. For example, there use to be a /tfp signature and now it is gone.

@@ -417,3 +435,49 @@ def test_acquire_token_obo(self):
result = cca.acquire_token_silent(downstream_scopes, account)
self.assertEqual(cca_result["access_token"], result["access_token"])

def _build_b2c_authority(self, policy):
base = "https://msidlabb2c.b2clogin.com/msidlabb2c.onmicrosoft.com"
return base + "/" + policy # We do not support base + "?p=" + policy

Choose a reason for hiding this comment

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

it's probably fine as supporting B2C in MSAL.Python it's a new feature.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To be clear, that inline comment is inside an internal test case, so it is more like a remind-to-ourselves, but did not mean it as a limitation or deficiency. In fact, currently all the public materials we can find, uses the "base/policy" format, rather than "base?p=policy" format. Such as:

That being said, I did heard from a previous internal presentation that the "base?p=policy" format would also work. We (the entire MSAL fleet) might actually want to switch to that format at a later time, because the current way - putting policy inside authority - has some intrinsic issues, but that is a different topic.

tests/test_e2e.py Outdated Show resolved Hide resolved
msal/authority.py Outdated Show resolved Hide resolved
if payload.get("error") == "invalid_instance":
raise ValueError(
"invalid_instance: "
"The authority you provided, %s, is not whitelisted. "
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe use "on the allow list" instead...idk.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually I thought about several options when I drafted that sentence. To me, "allow" does not sound right, because customer can of course choose a customized domain Contoso.com and we MSFT is in no position to disallow that. The precise cause of this error message is that the Contoso.com is not a so-called "well known" domain to MSFT Identity platform. And then again, it feels a bit weird to comment on other's name as "not well known", so I think "not whitelisted" sounds more neutral in tone. What do you think?

Copy link
Contributor

@jennyf19 jennyf19 left a comment

Choose a reason for hiding this comment

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

would like to see the actual developer experience, like what the developer would need to do. or i can just learn how to run your stuff, which i should do as well. :) I'm only concerned about sovereign clouds at this point. looking forward to further discussion.

ANSWERED inline by Ray: Because we managed to maintain the API surface unchanged, the actual developer experience is literally the same as non-B2C scenarios. Only when they need to use some B2C only behavior, such as Edit Profile in their web app, they develop a new page for it, which they would need to do anyway. See it in action in this sample PR.

Based on the way we implemented it,
the previous implementation would still work, in a sense that the app
dev would be guided to bypass the Instance Discovery.
This commit merely adds a shortcut so that app dev would not have to
explicitly toggle validate_authority=False.
@rayluo rayluo marked this pull request as ready for review October 15, 2019 15:48
@rayluo rayluo merged commit 1719e7e into dev Oct 15, 2019
@rayluo rayluo deleted the b2c branch October 15, 2019 21:49
@rayluo rayluo mentioned this pull request Oct 18, 2019
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.

Support Azure AD B2C
3 participants