diff --git a/src/Nox.Cli.PersonalAccessToken/AzDevOpsPatProvider.cs b/src/Nox.Cli.PersonalAccessToken/AzDevOpsPatProvider.cs index b2ad0cb..df2c869 100755 --- a/src/Nox.Cli.PersonalAccessToken/AzDevOpsPatProvider.cs +++ b/src/Nox.Cli.PersonalAccessToken/AzDevOpsPatProvider.cs @@ -27,7 +27,7 @@ public async Task GetPat(string accessToken) if (!string.IsNullOrEmpty(cachedPat)) { var pat = JsonConvert.DeserializeObject(cachedPat); - if (pat!.ValidTo < DateTime.Now) + if (pat!.ValidTo < DateTime.Now || !await ValidatePat(accessToken, pat.Token!)) { pat = await GetOrCreateOnlinePat(accessToken); } @@ -64,6 +64,16 @@ private async Task GetOrCreateOnlinePat(string accessToken) } } + private async Task ValidatePat(string accessToken, string pat) + { + var onlinePats = await GetOnlinePatList(accessToken); + if (onlinePats == null) return false; + var existing = onlinePats.PatTokens!.FirstOrDefault(p => p.Token == pat); + if (existing == null) return false; + if (existing.ValidTo < DateTime.Now) return false; + return true; + } + private async Task GetOnlinePatList(string accessToken) { var client = new RestClient($"https://vssps.dev.azure.com/{_organization}/_apis/tokens/pats?api-version=7.1-preview.1", options => diff --git a/src/Nox.Cli/Properties/launchSettings.json b/src/Nox.Cli/Properties/launchSettings.json index 0782971..e26c4ce 100755 --- a/src/Nox.Cli/Properties/launchSettings.json +++ b/src/Nox.Cli/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Nox.Cli": { "commandName": "Project", - "commandLineArgs": "new solution", + "commandLineArgs": "new dop", "workingDirectory": "/home/jan/demo/CliDemo", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development"