# airfare.py
age = int(input('How old are you? '))
if age <= 2:
print(' free')
elif 2 < age < 13:
print(' child fare)
else:
print('adult fare')
# comment
// comment
Page 1 / 1
def authenticate_azure(app):
accounts = app.get_accounts()
if accounts:
print("Taking the token silently")
creds = app.acquire_token_silent(SCOPES, account=accounts[0])
else:
print("Taking token interactively")
creds = app.acquire_token_interactive(scopes=SCOPES, port=PORT)
return creds
import atexit
import os
import asyncio
from cognite.client import CogniteClient,ClientConfig
from cognite.client.credentials import Token
from msal import PublicClientApplication, SerializableTokenCache
from cognite.client.data_classes import ExtractionPipeline
TENANT_ID = "<tenant_id>"
CLIENT_ID = "<client_id>"
CDF_CLUSTER = "<cluster>" // Ex: api, westeurope-1 etc
COGNITE_PROJECT = "<Your_Project>"
CACHE_FILENAME = "cache.bin"
BASE_URL = f"https://{CDF_CLUSTER}.cognitedata.com"
SCOPES = [f"https://{CDF_CLUSTER}.cognitedata.com/.default"]
AUTHORITY_HOST_URI = "https://login.microsoftonline.com"
AUTHORITY_URI = AUTHORITY_HOST_URI + "/" + TENANT_ID
PORT = 3000
app = PublicClientApplication(client_id=CLIENT_ID, authority=AUTHORITY_URI)
def create_cache():
cache = SerializableTokenCache()
if os.path.exists(CACHE_FILENAME):
cache.deserialize(open(CACHE_FILENAME, "r").read())
atexit.register(lambda:
open(CACHE_FILENAME, "w").write(cache.serialize()) if cache.has_state_changed else None
)
return cache
def authenticate_azure(app):
#Firstly, check the cache to see if this end user has signed in before
accounts = app.get_accounts()
if accounts:
print("Taking the token silently")
creds = app.acquire_token_silent(SCOPES, account=accounts[0])
else:
print("Taking token interactively")
creds = app.acquire_token_interactive(scopes=SCOPES, port=PORT)
return creds
app = PublicClientApplication(client_id=CLIENT_ID, authority=AUTHORITY_URI, token_cache=create_cache())
def get_token():
return authenticate_azure(app)["access_token"]
cnf = ClientConfig(client_name="my-special-client", project=COGNITE_PROJECT, credentials=Token(get_token), base_url=BASE_URL)
client = CogniteClient(cnf)
print(client.iam.token.inspect())
Reply
eiowrtireogj
No account yet? Sign up to Typeform or VideoAsk to join the community
Login with SSO
Login with LinkedInor
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.