Skip to content

Commit 549ee7a

Browse files
committed
Scaffoldwith test case
1 parent 404c5d3 commit 549ee7a

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

msal/application.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
3+
class ClientApplication(object):
4+
DEFAULT_AUTHORITY = "https://login.microsoftonline.com/common/"
5+
TOKEN_ENDPOINT_PATH = '/oauth2/v2.0/token'
6+
7+
def __init__(
8+
self, client_id,
9+
validate_authority=True, authority=DEFAULT_AUTHORITY):
10+
self.client_id = client_id
11+
self.validate_authority = validate_authority
12+
self.authority = authority
13+
# def aquire_token_silent(
14+
# self, scopes, user=None, authority=None, policy=None,
15+
# force_refresh=False):
16+
# pass
17+
18+
19+
class PublicClientApplication(ClientApplication):
20+
DEFAULT_REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"
21+
22+
def __init__(self, client_id, redirect_uri=DEFAULT_REDIRECT_URI, **kwargs):
23+
super(PublicClientApplication, self).__init__(client_id, **kwargs)
24+
self.redirect_uri = redirect_uri
25+
26+
class ConfidentialClientApplication(ClientApplication):
27+
def __init__(self, client_id, client_credential, user_token_cache, **kwargs):
28+
"""
29+
:param client_credential: It can be a string containing client secret,
30+
or an X509 certificate object.
31+
"""
32+
super(ConfidentialClientApplication, self).__init__(client_id, **kwargs)
33+
self.client_credential = client_credential
34+
self.user_token_cache = user_token_cache
35+
self.app_token_cache = None # TODO
36+
37+
def acquire_token_for_client(self, scope, policy=None): # Can policy default to None?
38+
pass
39+

tests/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import sys
2+
if sys.version_info[:2] < (2, 7):
3+
# The unittest module got a significant overhaul in Python 2.7,
4+
# so if we're in 2.6 we can use the backported version unittest2.
5+
import unittest2 as unittest
6+
else:
7+
import unittest
8+

tests/test_application.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from msal.application import ConfidentialClientApplication
2+
3+
from tests import unittest
4+
5+
6+
class TestConfidentialClientApplication(unittest.TestCase):
7+
def test_confidential_client_using_secret(self):
8+
app = ConfidentialClientApplication(
9+
"client_id", "client_secret", "TBD: TokenCache()")
10+
result = app.acquire_token_for_client(
11+
["r1/scope1", "r1/scope2"], "policy")
12+
self.assertIsNone(result)
13+

0 commit comments

Comments
 (0)