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

Corrected usage in comment of sample code #73

Merged
merged 1 commit into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions sample/certificate_credentials_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

def turn_on_logging():
logging.basicConfig(level=logging.DEBUG)
#or,
#or,
#handler = logging.StreamHandler()
#adal.set_logging_options({
# 'level': 'DEBUG',
# 'handler': handler
# 'handler': handler
#})
#handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))

Expand All @@ -20,8 +20,8 @@ def get_private_key(filename):
return private_pem

#
# You can provide account information by using a JSON file. Either
# through a command line argument, 'python sample.js parameters.json', or
# You can provide account information by using a JSON file. Either
# through a command line argument, 'python sample.py parameters.json', or
# specifying in an environment variable of ADAL_SAMPLE_PARAMETERS_FILE.
# privateKeyFile must contain a PEM encoded cert with private key.
# thumbprint must be the thumbprint of the privateKeyFile.
Expand All @@ -32,7 +32,7 @@ def get_private_key(filename):
# "thumbprint" : 'C15DEA8656ADDF67BE8031D85EBDDC5AD6C436E1',
# "privateKeyFile" : 'ncwebCTKey.pem'
# }
parameters_file = (sys.argv[1] if len(sys.argv) == 2 else
parameters_file = (sys.argv[1] if len(sys.argv) == 2 else
os.environ.get('ADAL_SAMPLE_PARAMETERS_FILE'))
sample_parameters = {}
if parameters_file:
Expand All @@ -43,7 +43,7 @@ def get_private_key(filename):
raise ValueError('Please provide parameter file with account information.')


authority_url = (sample_parameters['authorityHostUrl'] + '/' +
authority_url = (sample_parameters['authorityHostUrl'] + '/' +
sample_parameters['tenant'])
RESOURCE = '00000002-0000-0000-c000-000000000000'

Expand All @@ -54,9 +54,9 @@ def get_private_key(filename):
key = get_private_key(sample_parameters['privateKeyFile'])

token = context.acquire_token_with_client_certificate(
RESOURCE,
sample_parameters['clientId'],
key,
RESOURCE,
sample_parameters['clientId'],
key,
sample_parameters['thumbprint'])

print('Here is the token:')
Expand Down
14 changes: 7 additions & 7 deletions sample/client_credentials_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

def turn_on_logging():
logging.basicConfig(level=logging.DEBUG)
#or,
#or,
#handler = logging.StreamHandler()
#adal.set_logging_options({
# 'level': 'DEBUG',
# 'handler': handler
# 'handler': handler
#})
#handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))

# You can provide account information by using a JSON file. Either
# through a command line argument, 'python sample.js parameters.json', or
# through a command line argument, 'python sample.py parameters.json', or
# specifying in an environment variable of ADAL_SAMPLE_PARAMETERS_FILE.
# {
# "tenant" : "rrandallaad1.onmicrosoft.com",
Expand All @@ -24,7 +24,7 @@ def turn_on_logging():
# "clientSecret" : "verySecret=""
# }

parameters_file = (sys.argv[1] if len(sys.argv) == 2 else
parameters_file = (sys.argv[1] if len(sys.argv) == 2 else
os.environ.get('ADAL_SAMPLE_PARAMETERS_FILE'))

if parameters_file:
Expand All @@ -33,8 +33,8 @@ def turn_on_logging():
sample_parameters = json.loads(parameters)
else:
raise ValueError('Please provide parameter file with account information.')
authority_url = (sample_parameters['authorityHostUrl'] + '/' +

authority_url = (sample_parameters['authorityHostUrl'] + '/' +
sample_parameters['tenant'])
RESOURCE = '00000002-0000-0000-c000-000000000000'

Expand All @@ -45,7 +45,7 @@ def turn_on_logging():

token = context.acquire_token_with_client_credentials(
RESOURCE,
sample_parameters['clientId'],
sample_parameters['clientId'],
sample_parameters['clientSecret'])

print('Here is the token:')
Expand Down
12 changes: 6 additions & 6 deletions sample/device_code_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

def turn_on_logging():
logging.basicConfig(level=logging.DEBUG)
#or,
#or,
#handler = logging.StreamHandler()
#adal.set_logging_options({
# 'level': 'DEBUG',
# 'handler': handler
# 'handler': handler
#})
#handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))

# You can provide account information by using a JSON file
# with the same parameters as the sampleParameters variable below. Either
# through a command line argument, 'python sample.js parameters.json', or
# through a command line argument, 'python sample.py parameters.json', or
# specifying in an environment variable of ADAL_SAMPLE_PARAMETERS_FILE.
# {
# "tenant" : "rrandallaad1.onmicrosoft.com",
Expand All @@ -25,7 +25,7 @@ def turn_on_logging():
# "anothertenant" : "bar.onmicrosoft.com"
# }

parameters_file = (sys.argv[1] if len(sys.argv) == 2 else
parameters_file = (sys.argv[1] if len(sys.argv) == 2 else
os.environ.get('ADAL_SAMPLE_PARAMETERS_FILE'))

if parameters_file:
Expand All @@ -41,7 +41,7 @@ def turn_on_logging():
clientid = sample_parameters['clientid']
RESOURCE = '00000002-0000-0000-c000-000000000000'

#uncomment for verbose logging
#uncomment for verbose logging
#turn_on_logging()

context = adal.AuthenticationContext(authority_url)
Expand All @@ -56,7 +56,7 @@ def turn_on_logging():
another_tenant = sample_parameters.get('anothertenant')
if another_tenant:
authority_url = authority_host_url + '/' + another_tenant
#reuse existing cache which has the tokens acquired early on
#reuse existing cache which has the tokens acquired early on
existing_cache = context.cache
context = adal.AuthenticationContext(authority_url, cache=existing_cache)
token = context.acquire_token(RESOURCE, token['userId'], clientid)
Expand Down
12 changes: 6 additions & 6 deletions sample/refresh_token_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

def turn_on_logging():
logging.basicConfig(level=logging.DEBUG)
#or,
#or,
#handler = logging.StreamHandler()
#adal.set_logging_options({
# 'level': 'DEBUG',
# 'handler': handler
# 'handler': handler
#})
#handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))

# You can override the account information by using a JSON file. Either
# through a command line argument, 'python sample.js parameters.json', or
# through a command line argument, 'python sample.py parameters.json', or
# specifying in an environment variable of ADAL_SAMPLE_PARAMETERS_FILE.
# {
# "tenant" : "rrandallaad1.onmicrosoft.com",
Expand All @@ -25,7 +25,7 @@ def turn_on_logging():
# "password" : "verySecurePassword"
# }

parameters_file = (sys.argv[1] if len(sys.argv) == 2 else
parameters_file = (sys.argv[1] if len(sys.argv) == 2 else
os.environ.get('ADAL_SAMPLE_PARAMETERS_FILE'))

if parameters_file:
Expand All @@ -35,7 +35,7 @@ def turn_on_logging():
else:
raise ValueError('Please provide parameter file with account information.')

authority_url = (sample_parameters['authorityHostUrl'] + '/' +
authority_url = (sample_parameters['authorityHostUrl'] + '/' +
sample_parameters['tenant'])
RESOURCE = '00000002-0000-0000-c000-000000000000'

Expand All @@ -45,7 +45,7 @@ def turn_on_logging():
context = adal.AuthenticationContext(authority_url)

token = context.acquire_token_with_username_password(
RESOURCE,
RESOURCE,
sample_parameters['username'],
sample_parameters['password'],
sample_parameters['clientid'])
Expand Down
32 changes: 16 additions & 16 deletions sample/website_sample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
try:
try:
from http import server as httpserver
from http import cookies as Cookie
except ImportError:
Expand All @@ -24,7 +24,7 @@
from adal import AuthenticationContext

# You can provide account information by using a JSON file. Either
# through a command line argument, 'python sample.js parameters.json', or
# through a command line argument, 'python sample.py parameters.json', or
# specifying in an environment variable of ADAL_SAMPLE_PARAMETERS_FILE.
# {
# "tenant" : "rrandallaad1.onmicrosoft.com",
Expand All @@ -33,7 +33,7 @@
# "clientSecret" : "verySecret=""
# }

parameters_file = (sys.argv[1] if len(sys.argv) == 2 else
parameters_file = (sys.argv[1] if len(sys.argv) == 2 else
os.environ.get('ADAL_SAMPLE_PARAMETERS_FILE'))

if parameters_file:
Expand All @@ -44,13 +44,13 @@
raise ValueError('Please provide parameter file with account information.')

PORT = 8088
TEMPLATE_AUTHZ_URL = ('https://login.windows.net/{}/oauth2/authorize?'+
TEMPLATE_AUTHZ_URL = ('https://login.windows.net/{}/oauth2/authorize?'+
'response_type=code&client_id={}&redirect_uri={}&'+
'state={}&resource={}')
RESOURCE = '00000002-0000-0000-c000-000000000000' #Graph Resource
REDIRECT_URI = 'http://localhost:{}/getAToken'.format(PORT)

authority_url = (sample_parameters['authorityHostUrl'] + '/' +
authority_url = (sample_parameters['authorityHostUrl'] + '/' +
sample_parameters['tenant'])

class OAuth2RequestHandler(httpserver.SimpleHTTPRequestHandler):
Expand All @@ -61,16 +61,16 @@ def do_GET(self):
self.send_header('Location', login_url)
self.end_headers()
elif self.path == '/login':
auth_state = (''.join(random.SystemRandom()
auth_state = (''.join(random.SystemRandom()
.choice(string.ascii_uppercase + string.digits)
for _ in range(48)))
cookie = Cookie.SimpleCookie()
cookie['auth_state'] = auth_state
authorization_url = TEMPLATE_AUTHZ_URL.format(
sample_parameters['tenant'],
sample_parameters['clientId'],
REDIRECT_URI,
auth_state,
sample_parameters['tenant'],
sample_parameters['clientId'],
REDIRECT_URI,
auth_state,
RESOURCE)
self.send_response(307)
self.send_header('Set-Cookie', cookie.output(header=''))
Expand All @@ -88,13 +88,13 @@ def do_GET(self):
sample_parameters['clientId'],
RESOURCE,
sample_parameters['clientSecret'])
message = (message + '*** And here is the refresh response:' +
message = (message + '*** And here is the refresh response:' +
json.dumps(token_response))
except ValueError as exp:
message = str(exp)
is_ok = False
self._send_response(message, is_ok)

def _acquire_token(self):
parsed = urlparse(self.path)
code = parse_qs(parsed.query)['code'][0]
Expand All @@ -104,10 +104,10 @@ def _acquire_token(self):
raise ValueError('state does not match')
auth_context = AuthenticationContext(authority_url)
return auth_context.acquire_token_with_authorization_code(
code,
REDIRECT_URI,
RESOURCE,
sample_parameters['clientId'],
code,
REDIRECT_URI,
RESOURCE,
sample_parameters['clientId'],
sample_parameters['clientSecret'])

def _send_response(self, message, is_ok=True):
Expand Down