def _acquire_token_with_client_certificate( authority, client_id, certificate, thumbprint, resource=None, validate_authority=True ): ''' TODO: Verify the use of this method so we can complete testing before exposing Acquires a token when given a client certificate and other information. Args: authority (str): Your authority will have the form 'https://login.windows.net/ABCDEFGH-1234-ABCD-1234-ABCDEFGHIJKL'. You must retrieve the this URI + GUID for your tenant. You can find this on the Azure Active Directory Application Configure page and click view endpoints. This string will be the root of the connection links given. client_id (str): The id of your client. Found on the configure page of Azure Active Directory Applications. certificate (str): The certificate for the token you are getting. thumbprint (str): The thumbprint of the certificate. resource (str, optional): The resource you are accessing. Defaults to 'https://management.core.windows.net/'. validate_authority (bool, optional): Indicates whether you want the authority validated. Defaults to True. Returns: dict: a dict with the following keys: 'accessToken', 'expiresIn', 'expiresOn', 'familyName', 'givenName', 'isUserIdDisplayable', 'refreshToken', 'resource', 'tenantId', 'tokenType', 'userId' ''' resource = resource or _DefaultValues.resource argument.validate_string_param(authority, 'authority') argument.validate_string_param(client_id, 'client_id') argument.validate_string_param(certificate, 'certificate') argument.validate_string_param(thumbprint, 'thumbprint') argument.validate_string_param(resource, 'resource') context = AuthenticationContext(authority, validate_authority) token_responses = [] def callback(err, token_response): if err: raise Exception("Error:{} token_response:{}".format(err, token_response)) token_responses.append(token_response) def token_func(context): context.token_request = TokenRequest(context._call_context, context, client_id, resource) context.token_request.get_token_with_certificate(certificate, thumbprint, callback) context._acquire_token(callback, token_func) return token_responses[0]
def acquire_token_with_username_password( authority, username, password, client_id=None, resource=None, validate_authority=True ): ''' Acquires a token when given a username and password combination. Args: authority (str): Your authority will have the form 'https://login.windows.net/ABCDEFGH-1234-ABCD-1234-ABCDEFGHIJKL'. You must retrieve the this URI + GUID for your tenant. You can find this on the Azure Active Directory Application Configure page and click view endpoints. This string will be the root of the connection links given. username (str): Your username in the form [email protected]. password (str): Your password. client_id (str, optional): The id of your client. For username password we use the XPlat Client Id by default. resource (str, optional): The resource you are accessing. Defaults to 'https://management.core.windows.net/'. validate_authority (bool, optional): Indicates whether you want the authority validated. Defaults to True. Returns: dict: a dict with the following keys: 'accessToken', 'expiresIn', 'expiresOn', 'familyName', 'givenName', 'isUserIdDisplayable', 'refreshToken', 'resource', 'tenantId', 'tokenType', 'userId' ''' resource = resource or _DefaultValues.resource client_id = client_id or _DefaultValues.client_id argument.validate_string_param(authority, 'authority') argument.validate_string_param(client_id, 'client_id') argument.validate_string_param(username, 'username') argument.validate_string_param(password, 'password') argument.validate_string_param(resource, 'resource') context = AuthenticationContext(authority, validate_authority) token_responses = [] def callback(err, token_response): if err: raise Exception("Error:{} token_response:{}".format(err, token_response)) token_responses.append(token_response) def token_func(context): context.token_request = TokenRequest(context._call_context, context, client_id, resource) context.token_request._get_token_with_username_password(username, password, callback) context._acquire_token(callback, token_func) return token_responses[0]
def acquire_token_with_client_credentials( authority, client_id, client_secret, resource=None, validate_authority=True ): ''' Acquires a token when given a set of client credentials. Args: authority (str): Your authority will have the form 'https://login.windows.net/ABCDEFGH-1234-ABCD-1234-ABCDEFGHIJKL'. You must retrieve the this URI + GUID for your tenant. You can find this on the Azure Active Directory Application Configure page and click view endpoints. This string will be the root of the connection links given. client_id (str): The id of your client. Found on the configure page of Azure Active Directory Applications. client_secret (str): The client secret used to get the token. You can create a secret on the configure page of an Azure Active Directory Application resource (str, optional): The resource you are accessing. Defaults to 'https://management.core.windows.net/'. validate_authority (bool, optional): Indicates whether you want the authority validated. Defaults to True. Returns: dict: a dict with the following keys: 'accessToken', 'expiresIn', 'expiresOn', 'resource', 'tokenType'. ''' resource = resource or _DefaultValues.resource argument.validate_string_param(authority, 'authority') argument.validate_string_param(client_id, 'client_id') argument.validate_string_param(client_secret, 'client_secret') argument.validate_string_param(resource, 'resource') context = AuthenticationContext(authority, validate_authority) token_responses = [] def callback(err, token_response): if err: raise Exception("Error:{} token_response:{}".format(err, token_response)) token_responses.append(token_response) def token_func(context, extra=None): context.token_request = TokenRequest(context._call_context, context, client_id, resource) context.token_request._get_token_with_client_credentials(client_secret, callback) context._acquire_token(callback, token_func) return token_responses[0]