Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Introduce a parameter AuthenticationContext(..., api_version='1.0') #57

Merged
merged 4 commits into from
Nov 18, 2016

Conversation

rayluo
Copy link
Collaborator

@rayluo rayluo commented Nov 17, 2016

In an attempt to fix #54 yet maintain backward compatibility, this PR introduces a parameter AuthenticationContext(..., api_version='1.0') to turn on/off api-version behavior.

  • Legacy ADAL-python customers can safely upgrade to the upcoming new version which contains this adjustment. By default, your current code will still work with the SAME behavior as before.
  • However, to ensure a smooth transition, we recommend the current ADAL-python customers to try out the new behavior by explicitly set context = AuthenticationContext(..., api_version=None), to confirm that your app will work fine with this new direction.
  • New ADAL-python customers shall use context = AuthenticationContext(..., api_version=None) too. In future, this switch will have a default value as None.

@rayluo rayluo force-pushed the switch-for-api-version branch from ef62699 to df4c7ba Compare November 17, 2016 18:47
Copy link
Contributor

@yugangw-msft yugangw-msft left a comment

Choose a reason for hiding this comment

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

LGTM. Left one comment for clarification. Feel free to merge after that

def test_explicitly_turn_off_api_version(self):
context = adal.AuthenticationContext(
"https://login.windows.net/tenant", api_version=None)
self.assertEqual(context._call_context['api_version'], None)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we verify there is no warning emitted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't normally verify "no warning emitted" but in this particular case, sure I can do that. New commit is coming soon.

warnings.warn(
"""The default behavior of including api-version=1.0 on the wire
is now deprecated.
Future version of ADAL will change the default value to None.
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is we will just remove this parameter in future, as adal is not a protocol library. If yes, let us change warning words accordingly such as
Future version of ADAL will remove this parameter and use more recent and better version

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah that is the tricky part which is not yet set on stone.

When we choose to maintain the backward compatibility of previous api-version=1.0 behavior by default, from now on the majority of current customers and new customers (those whom got bitten by issue #54 and/or whom be persuaded by the warning message in this PR), would then have to do AuthenticationContext(..., api_version=None) explicitly. And this situation will last for quite a while until the next major version bump on ADAL. So lots of customers will be on the api_version=None side. By the time, we will have 2 options moving forward:

  1. We may choose to completely remove the api_version=... parameter with a major version bump. That would be a HARD breaking change, because all customers who follow our advice this time would then have to change their code again to remove the api_version=None.
  2. Or we may choose to keep the api_version=... parameter in the API signature, we just will not use it anymore, i.e. it will become a NO-OP. That way it will still be a subtle breaking change (and also shipped with a major version bump), but current AuthenticationContext(..., api_version=None) customers would not need to change their code.

All these sound more complicated than simply remove api_version completely and immediately, but this is the price to pay for the backward compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rayluo, it is your call. I am fine with either way

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that any developers are going to understand that warning. Client developers don't care about the protocol at all, and also don't have visibility in to the claims in the token. They may know nothing about the effect of the api-version QP on the claims in the token and how that might break a service. I don't think that I would put that warning in.

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 have to admit that there is no way to convey the complicated history into this several sentences long warning message. :-( Regardless of the wording, the main purpose of such warning message was trying to say "hey api_version=None is the future, you'd better opt-in (and then test out the new behaviors) now, rather than facing a sudden change in a future major version update".

Copy link
Contributor

Choose a reason for hiding this comment

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

My 2 cents
@rayluo, can we consider to downgrading the level to an info, not a warn? My concern is the warning by default will spit out everywhere to end users even for working applications which don't directly uses adal, but get pulled in by its dependencies. I hope such change should have zero end users impacts for most client applications.
At the same time, we probably should update the method's doc-string to describe this parameter, so at least developers coding with adal will know the impact and do the recommended way

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That makes sense. And it seems an easy fix at this point would be changing the warning type to DeprecationWarning, which will then be ignored by default, I've tested it by running python -c "import adal; adal.AuthenticationContext('https://login.windows.net/tenant')" on both Python 2 and Python 3.

I've also add docstring for the new parameter. Please review the latest commit

@rayluo rayluo force-pushed the switch-for-api-version branch 2 times, most recently from b2a1d92 to 2cf828b Compare November 17, 2016 21:47
@rayluo rayluo force-pushed the switch-for-api-version branch from 2cf828b to 86570a1 Compare November 17, 2016 22:35
@rayluo
Copy link
Collaborator Author

rayluo commented Nov 17, 2016

Note: we will need a little more time to investigate the current test failure on Travis-CI. It is not a major issue though, it is just that the warning message is not showing up on Travis-CI's test environment which is Python 2.7.9 running on Ubuntu 12.04. FWIW, I've manually tested this PR on Python 2.7.12 & Python 3.5.2 on Windows, and Python 2.7.10 on OSX, they all work. UPDATE: I also test on Python 2.7.9 on Ubuntu 16.04, it still works. So Python 2.7.9 is not the culprit.

@yugangw-msft
Copy link
Contributor

@rayluo, maybe you can just use the built-in logging in adal and wire up your test handler. I am not familiar with warnings package, but handler works for my test added recently

@rayluo
Copy link
Collaborator Author

rayluo commented Nov 18, 2016

@yugangw-msft Besides their subtle conceptual difference:

warnings.warn() in library code if the issue is avoidable and the client application should be modified to eliminate the warning

logging.warning() if there is nothing the client application can do about the situation, but the event should still be noted

One noticeable difference is for i in range(10): warnings.warn("foo") will only print out one output by default. And my guess is, this exact smart feature somehow causes the test counter not counting properly (on Travis-CI for unknown reason), hence the test failure.

Using logging instead, or using warnings with its "always warning" mode, would pass that test case, but it results in tons of duplicated warning messages showing up on the console when running our unit tests.

In this particular case, I guess I would simply relax that assertion to make the test cases pass. After all, it is just some optional warning message, for a behavior which will eventually be replaced by next major version update.

@rayluo rayluo force-pushed the switch-for-api-version branch from c362c3b to 828cd05 Compare November 18, 2016 17:00
@yugangw-msft
Copy link
Contributor

🚢 Thanks @rayluo !

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

Successfully merging this pull request may close these issues.

retrieved token does not grant access to related resource (401 Error)
3 participants