Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azure-communication-identity] Fixed typing issue for mypy #33965

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

class CommunicationIdentityClientSamples(object):
def __init__(self):
self.connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING")
self.connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING", "")
self.client_id = os.getenv("AZURE_CLIENT_ID")
self.client_secret = os.getenv("AZURE_CLIENT_SECRET")
self.tenant_id = os.getenv("AZURE_TENANT_ID")
self.m365_client_id = os.getenv("COMMUNICATION_M365_APP_ID")
self.m365_client_id = os.getenv("COMMUNICATION_M365_APP_ID", "")
self.m365_aad_authority = os.getenv("COMMUNICATION_M365_AAD_AUTHORITY")
self.m365_aad_tenant = os.getenv("COMMUNICATION_M365_AAD_TENANT")
self.msal_username = os.getenv("COMMUNICATION_MSAL_USERNAME")
Expand Down Expand Up @@ -64,11 +64,11 @@ def get_token(self):
self.connection_string
)
user = identity_client.create_user()
print("Getting token for: " + user.properties.get("id"))
print(f"Getting token for: {user.properties.get('id')}")
tokenresponse = identity_client.get_token(
user, scopes=[CommunicationTokenScope.CHAT]
)
print("Token issued with value: " + tokenresponse.token)
print(f"Token issued with value: {tokenresponse.token}")

def get_token_with_custom_expiration(self):
from azure.communication.identity import (
Expand All @@ -92,14 +92,14 @@ def get_token_with_custom_expiration(self):
self.connection_string
)
user = identity_client.create_user()
print("Getting token for: " + user.properties.get("id"))
print(f"Getting token for: {user.properties.get('id')}")
token_expires_in = timedelta(hours=1)
tokenresponse = identity_client.get_token(
user,
scopes=[CommunicationTokenScope.CHAT],
token_expires_in=token_expires_in,
)
print("Issued token with custom expiration" + tokenresponse.token)
print(f"Issued token with custom expiration {tokenresponse.token}")

def revoke_tokens(self):
from azure.communication.identity import (
Expand All @@ -126,9 +126,9 @@ def revoke_tokens(self):
tokenresponse = identity_client.get_token(
user, scopes=[CommunicationTokenScope.CHAT]
)
print("Revoking token: " + tokenresponse.token)
print(f"Revoking token: {tokenresponse.token}")
identity_client.revoke_tokens(user)
print(tokenresponse.token + " revoked successfully")
print(f"{tokenresponse.token} revoked successfully")

def create_user(self):
from azure.communication.identity import CommunicationIdentityClient
Expand All @@ -150,7 +150,7 @@ def create_user(self):
)
print("Creating new user")
user = identity_client.create_user()
print("User created with id:" + user.properties.get("id"))
print(f"User created with id: {user.properties.get('id')}")

def create_user_and_token(self):
from azure.communication.identity import (
Expand All @@ -177,8 +177,8 @@ def create_user_and_token(self):
user, tokenresponse = identity_client.create_user_and_token(
scopes=[CommunicationTokenScope.CHAT]
)
print("User created with id:" + user.properties.get("id"))
print("Token issued with value: " + tokenresponse.token)
print(f"User created with id: {user.properties.get('id')}")
print(f"Token issued with value: {tokenresponse.token}")

def create_user_and_token_with_custom_expiration(self):
from azure.communication.identity import (
Expand Down Expand Up @@ -206,8 +206,8 @@ def create_user_and_token_with_custom_expiration(self):
user, tokenresponse = identity_client.create_user_and_token(
scopes=[CommunicationTokenScope.CHAT], token_expires_in=token_expires_in
)
print("User created with id:" + user.properties.get("id"))
print("Issued token with custom expiration: " + tokenresponse.token)
print(f"User created with id: {user.properties.get('id')}")
print(f"Issued token with custom expiration: {tokenresponse.token}")

def delete_user(self):
from azure.communication.identity import CommunicationIdentityClient
Expand All @@ -228,9 +228,9 @@ def delete_user(self):
self.connection_string
)
user = identity_client.create_user()
print("Deleting user: " + user.properties.get("id"))
print(f"Deleting user: {user.properties.get('id')}")
identity_client.delete_user(user)
print(user.properties.get("id") + " deleted")
print(f"{user.properties.get('id')} deleted")

def get_token_for_teams_user(self):
if os.getenv("SKIP_INT_IDENTITY_EXCHANGE_TOKEN_TEST") == "true":
Expand Down Expand Up @@ -267,12 +267,12 @@ def get_token_for_teams_user(self):
)
aad_token = result["access_token"]
teams_user_oid = result["id_token_claims"]["oid"]
print("AAD access token of a Teams User: " + aad_token)
print(f"AAD access token of a Teams User: {aad_token}")

tokenresponse = identity_client.get_token_for_teams_user(
aad_token, self.m365_client_id, teams_user_oid
)
print("Token issued with value: " + tokenresponse.token)
print(f"Token issued with value: {tokenresponse.token}")


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@

class CommunicationIdentityClientSamples(object):
def __init__(self):
self.connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING")
self.connection_string = os.getenv("COMMUNICATION_SAMPLES_CONNECTION_STRING", "")
self.endpoint = os.getenv("AZURE_COMMUNICATION_SERVICE_ENDPOINT")
self.client_id = os.getenv("AZURE_CLIENT_ID")
self.client_secret = os.getenv("AZURE_CLIENT_SECRET")
self.tenant_id = os.getenv("AZURE_TENANT_ID")
self.m365_client_id = os.getenv("COMMUNICATION_M365_APP_ID")
self.m365_client_id = os.getenv("COMMUNICATION_M365_APP_ID", "")
self.m365_aad_authority = os.getenv("COMMUNICATION_M365_AAD_AUTHORITY")
self.m365_aad_tenant = os.getenv("COMMUNICATION_M365_AAD_TENANT")
self.msal_username = os.getenv("COMMUNICATION_MSAL_USERNAME")
Expand Down Expand Up @@ -67,11 +67,11 @@ async def get_token(self):

async with identity_client:
user = await identity_client.create_user()
print("Issuing token for: " + user.properties.get("id"))
print(f"Issuing token for: {user.properties.get('id')}")
tokenresponse = await identity_client.get_token(
user, scopes=[CommunicationTokenScope.CHAT]
)
print("Token issued with value: " + tokenresponse.token)
print(f"Token issued with value: {tokenresponse.token}")

async def get_token_with_custom_expiration(self):
from azure.communication.identity.aio import CommunicationIdentityClient
Expand All @@ -95,14 +95,14 @@ async def get_token_with_custom_expiration(self):

async with identity_client:
user = await identity_client.create_user()
print("Issuing token for: " + user.properties.get("id"))
print(f"Issuing token for: {user.properties.get('id')}")
token_expires_in = timedelta(hours=1)
tokenresponse = await identity_client.get_token(
user,
scopes=[CommunicationTokenScope.CHAT],
token_expires_in=token_expires_in,
)
print("Issued token with custom expiration: " + tokenresponse.token)
print(f"Issued token with custom expiration: {tokenresponse.token}")

async def revoke_tokens(self):
from azure.communication.identity.aio import CommunicationIdentityClient
Expand All @@ -129,9 +129,9 @@ async def revoke_tokens(self):
tokenresponse = await identity_client.get_token(
user, scopes=[CommunicationTokenScope.CHAT]
)
print("Revoking token: " + tokenresponse.token)
print(f"Revoking token: {tokenresponse.token}")
await identity_client.revoke_tokens(user)
print(tokenresponse.token + " revoked successfully")
print(f"{tokenresponse.token} revoked successfully")

async def create_user(self):
from azure.communication.identity.aio import CommunicationIdentityClient
Expand All @@ -155,7 +155,7 @@ async def create_user(self):
async with identity_client:
print("Creating new user")
user = await identity_client.create_user()
print("User created with id:" + user.properties.get("id"))
print(f"User created with id: {user.properties.get('id')}")

async def create_user_and_token(self):
from azure.communication.identity.aio import CommunicationIdentityClient
Expand All @@ -182,8 +182,8 @@ async def create_user_and_token(self):
user, tokenresponse = await identity_client.create_user_and_token(
scopes=[CommunicationTokenScope.CHAT]
)
print("User created with id:" + user.properties.get("id"))
print("Token issued with value: " + tokenresponse.token)
print(f"User created with id: {user.properties.get('id')}")
print(f"Token issued with value: {tokenresponse.token}")

async def create_user_and_token_with_custom_expiration(self):
from azure.communication.identity.aio import CommunicationIdentityClient
Expand Down Expand Up @@ -211,8 +211,8 @@ async def create_user_and_token_with_custom_expiration(self):
user, tokenresponse = await identity_client.create_user_and_token(
scopes=[CommunicationTokenScope.CHAT], token_expires_in=token_expires_in
)
print("User created with id:" + user.properties.get("id"))
print("Issued token with custom expiration: " + tokenresponse.token)
print(f"User created with id: {user.properties.get('id')}")
print(f"Issued token with custom expiration: {tokenresponse.token}")

async def delete_user(self):
from azure.communication.identity.aio import CommunicationIdentityClient
Expand All @@ -235,9 +235,9 @@ async def delete_user(self):

async with identity_client:
user = await identity_client.create_user()
print("Deleting user: " + user.properties.get("id"))
print(f"Deleting user: {user.properties.get('id')}")
await identity_client.delete_user(user)
print(user.properties.get("id") + " deleted")
print(f"{user.properties.get('id')} deleted")

async def get_token_for_teams_user(self):
if os.getenv("SKIP_INT_IDENTITY_EXCHANGE_TOKEN_TEST") == "true":
Expand Down Expand Up @@ -275,12 +275,12 @@ async def get_token_for_teams_user(self):
)
aad_token = result["access_token"]
teams_user_oid = result["id_token_claims"]["oid"]
print("AAD access token of a Teams User: " + aad_token)
print(f"AAD access token of a Teams User: {aad_token}")

tokenresponse = await identity_client.get_token_for_teams_user(
aad_token, self.m365_client_id, teams_user_oid
)
print("Token issued with value: " + tokenresponse.token)
print(f"Token issued with value: {tokenresponse.token}")


async def main():
Expand Down