Repository: Azure/msrest-for-python

Issue:
Make BasicTokenAuthentication the new base class of OAuthTokenAuthentication
To enable some KV scenarios releated to MSI

Discussion:

Patch:
diff --git a/msrest/authentication.py b/msrest/authentication.py
index 48c90ae..8d21624 100644
--- a/msrest/authentication.py
+++ b/msrest/authentication.py
@@ -79,6 +79,14 @@ class BasicTokenAuthentication(Authentication):
         self.scheme = 'Bearer'
         self.token = token
 
+    def set_token(self):
+        """Should be used to define the self.token attribute.
+
+        In this implementation, does nothing since the token is statically provided
+        at creation.
+        """
+        pass
+
     def signed_session(self):
         """Create requests session with any required auth headers
         applied.
@@ -91,7 +99,7 @@ class BasicTokenAuthentication(Authentication):
         return session
 
 
-class OAuthTokenAuthentication(Authentication):
+class OAuthTokenAuthentication(BasicTokenAuthentication):
     """OAuth Token Authentication.
     Requires that supplied token contains an expires_in field.
 


Test patch:
diff --git a/tests/test_auth.py b/tests/test_auth.py
index e573a02..32f67f5 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -39,6 +39,7 @@ except ImportError:
 
 from msrest.authentication import (
     BasicAuthentication,
+    BasicTokenAuthentication,
     OAuthTokenAuthentication)
 
 from requests import Request
@@ -71,6 +72,19 @@ class TestAuthentication(unittest.TestCase):
         self.assertTrue('Authorization' in req.headers)
         self.assertTrue(req.headers['Authorization'].startswith('Basic '))
 
+    def test_basic_token_auth(self):
+
+        token = {
+            'access_token': '123456789'
+        }
+        basic = BasicTokenAuthentication(token)
+        basic.set_token() # Just check that this does not raise
+        session = basic.signed_session()
+
+        req = session.prepare_request(self.request)
+        self.assertTrue('Authorization' in req.headers)
+        self.assertEquals(req.headers['Authorization'], 'Bearer 123456789')
+
     def test_token_auth(self):
 
         token =  {"my_token":123}