Skip to content
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
34 changes: 0 additions & 34 deletions src/azure-cli-core/azure/cli/core/_msal.py

This file was deleted.

21 changes: 6 additions & 15 deletions src/azure-cli-core/azure/cli/core/_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,16 @@ def get_msal_token(self, scopes, data):
This is added only for vmssh feature.
It is a temporary solution and will deprecate after MSAL adopted completely.
"""
from msal import ClientApplication
import posixpath
account = self.get_subscription()
username = account[_USER_ENTITY][_USER_NAME]
tenant = account[_TENANT_ID] or 'common'
_, refresh_token, _, _ = self.get_refresh_token()
certificate = self._creds_cache.retrieve_msal_token(tenant, scopes, data, refresh_token)
return username, certificate
authority = posixpath.join(self.cli_ctx.cloud.endpoints.active_directory, tenant)
app = ClientApplication(_CLIENT_ID, authority=authority)
result = app.acquire_token_by_refresh_token(refresh_token, scopes, data=data)
return username, result["access_token"]

def get_refresh_token(self, resource=None,
subscription=None):
Expand Down Expand Up @@ -1071,19 +1075,6 @@ def retrieve_token_for_user(self, username, tenant, resource):
self.persist_cached_creds()
return (token_entry[_TOKEN_ENTRY_TOKEN_TYPE], token_entry[_ACCESS_TOKEN], token_entry)

def retrieve_msal_token(self, tenant, scopes, data, refresh_token):
"""
This is added only for vmssh feature.
It is a temporary solution and will deprecate after MSAL adopted completely.
"""
from azure.cli.core._msal import AdalRefreshTokenBasedClientApplication
tenant = tenant or 'organizations'
authority = self._ctx.cloud.endpoints.active_directory + '/' + tenant
app = AdalRefreshTokenBasedClientApplication(_CLIENT_ID, authority=authority)
result = app.acquire_token_silent(scopes, None, data=data, refresh_token=refresh_token)

return result["access_token"]

def retrieve_token_for_service_principal(self, sp_id, resource, tenant, use_cert_sn_issuer=False):
self.load_adal_token_cache()
matched = [x for x in self._service_principal_creds if sp_id == x[_SERVICE_PRINCIPAL_ID]]
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ def test_find_using_specific_tenant(self, _get_authorization_code_mock, mock_aut
self.assertEqual(all_subscriptions[0].home_tenant_id, home_tenant)

@mock.patch('azure.cli.core._profile.CredsCache.retrieve_token_for_user', autospec=True)
@mock.patch('azure.cli.core._msal.AdalRefreshTokenBasedClientApplication._acquire_token_silent_by_finding_specific_refresh_token', autospec=True)
@mock.patch('msal.ClientApplication.acquire_token_by_refresh_token', autospec=True)
def test_get_msal_token(self, mock_acquire_token, mock_retrieve_token_for_user):
"""
This is added only for vmssh feature.
Expand Down
3 changes: 1 addition & 2 deletions src/azure-cli-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
'humanfriendly>=4.7,<10.0',
'jmespath',
'knack==0.8.0rc2',
'msal~=1.0.0',
'msal-extensions~=0.1.3',
'msal~=1.9',
'msrestazure>=0.6.3',
'paramiko>=2.0.8,<3.0.0',
'PyJWT==1.7.1',
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-telemetry/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
classifiers=CLASSIFIERS,
install_requires=[
'applicationinsights>=0.11.1,<0.12',
'portalocker~=1.2',
'portalocker~=1.6',
],
packages=[
'azure.cli.telemetry',
Expand Down
3 changes: 2 additions & 1 deletion src/azure-cli/requirements.py3.Darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ jsmin==2.2.2
knack==0.8.0rc2
MarkupSafe==1.1.1
mock==4.0.2
msal==1.9.0
msrest==0.6.21
msrestazure==0.6.3
oauthlib==3.0.1
paramiko==2.6.0
pbr==5.3.1
portalocker==1.4.0
portalocker==1.7.1
psutil==5.7.2
pycparser==2.19
PyJWT==1.7.1
Expand Down
3 changes: 2 additions & 1 deletion src/azure-cli/requirements.py3.Linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ jsmin==2.2.2
knack==0.8.0rc2
MarkupSafe==1.1.1
mock==4.0.2
msal==1.9.0
msrest==0.6.21
msrestazure==0.6.3
oauthlib==3.0.1
paramiko==2.6.0
pbr==5.3.1
portalocker==1.4.0
portalocker==1.7.1
psutil==5.7.2
pycparser==2.19
PyJWT==1.7.1
Expand Down
3 changes: 2 additions & 1 deletion src/azure-cli/requirements.py3.windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ jsmin==2.2.2
knack==0.8.0rc2
MarkupSafe==1.1.1
mock==4.0.2
msal==1.9.0
msrest==0.6.21
msrestazure==0.6.3
oauthlib==3.0.1
paramiko==2.6.0
pbr==5.3.1
portalocker==1.2.1
portalocker==1.7.1
psutil==5.7.2
pycparser==2.19
PyJWT==1.7.1
Expand Down