starting and stopping the fabric instance in azure does not work using service principal
TarekSalha opened this issue · comments
Hey, I am currently testing the sdk, but get an error message, when trying to do
azureClient = FabricAzureClient(
tenant_id=CONFIG.tenant_id,
client_id=CONFIG.client_id,
client_secret=CONFIG.client_secret
)
response = azureClient.get_capacity(CONFIG.subscription_id, CONFIG.resource_group_name, CONFIG.vm_name)
the method does not return a token at get_token()
in your code:
class FabricServicePrincipal(FabricAuth):
"""FabricServicePrincipal class to interact with Entra ID"""
def __init__(self, tenant_id, client_id, client_secret, scope, silent = False):
super().__init__(scope)
if not silent:
print("Using Service Principal for authentication")
self.tenant_id = tenant_id
self.client_id = client_id
self.client_secret = client_secret
def get_token(self):
"""Get token from Azure AD"""
# Get token from Azure AD
url = f"https://login.microsoftonline.com/{self.tenant_id}/oauth2/v2.0/token"
payload = {
'grant_type': 'client_credentials',
'client_id': f'{self.client_id}',
'client_secret': f'{self.client_secret}',
'scope': self.scope
}
response = requests.post(url, data=payload)
access_token = response.json().get('access_token')
return access_token
From my debugging, I would conclude, this is because you are giving the get_token()
method the wrong scope. You are initializing the scope here to https://management.azure.com/
but from what I can see, it should be https://management.azure.com/.default
class FabricAzureClient(FabricClient):
def __init__(self, tenant_id=None, client_id=None, client_secret=None, silent=False) -> None:
super().__init__(scope = "https://management.azure.com/",
tenant_id = tenant_id,
client_id = client_id,
client_secret = client_secret,
silent = silent)
with this changed configuration, I am able to successfully get a token.
Cheers, Tarek
PS: I just created a PR regarding the issue ;-)
#6