azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

TokenCache is not getting populated after clearing context and then logging in.

Open jefffanjoy opened this issue 8 years ago • 1 comments

Description

Token cache is not getting populated after clearing context and then logging in. Context is generated but the TokenCache property does not get populated as expected so that an access token can be retrieved.

Script/Steps for Reproduction

Clear-AzureRMContext -Scope -Process -Force
Connect-AzureRmAccount
$context = Get-AzureRmContext
$context.TokenCache.ReadItems()

Module Version

> Get-Module AzureRM -ListAvailable


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     6.4.0      AzureRM

Environment Data

Name                           Value
----                           -----
PSVersion                      5.1.17134.165
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.165
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Debug Output

> $context = Get-AzureRmContext
DEBUG: 8:33:29 PM - GetAzureRMContextCommand begin processing with ParameterSet 'GetSingleContext'.
DEBUG: 8:33:29 PM - using account id '[email protected]'...
DEBUG: AzureQoSEvent: CommandName - Get-AzureRmContext; IsSuccess - True; Duration - 00:00:00.0068135; Exception - ;
DEBUG: Finish sending metric.
DEBUG: 8:33:30 PM - GetAzureRMContextCommand end processing.
DEBUG: 8:33:30 PM - GetAzureRMContextCommand end processing.

jefffanjoy avatar Jul 15 '18 23:07 jefffanjoy

Apparently it has to do with auto save settings. Since I'm clearing at the process scope, running Enable-AzureRmContextAutoSave -Scope Process allows the saving of the context at the process scope which then successfully seems to write the tokencache.

jefffanjoy avatar Jul 16 '18 04:07 jefffanjoy