From 5fede34375afac275ae2ba4a9226f56b0cb74bf3 Mon Sep 17 00:00:00 2001 From: Oren Novotny Date: Sun, 1 Jul 2018 14:24:59 -0400 Subject: [PATCH 1/2] Add a better error message if it's a bad user/pass --- src/Directory.build.props | 4 ++++ src/SignClient/SignCommand.cs | 29 +++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Directory.build.props b/src/Directory.build.props index 547b6e5f..123bc3ae 100644 --- a/src/Directory.build.props +++ b/src/Directory.build.props @@ -1,10 +1,14 @@ latest + true + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + \ No newline at end of file diff --git a/src/SignClient/SignCommand.cs b/src/SignClient/SignCommand.cs index dc4a467a..2427aab4 100644 --- a/src/SignClient/SignCommand.cs +++ b/src/SignClient/SignCommand.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Net.Http; +using System.Security.Authentication; using System.Threading.Tasks; using Microsoft.Extensions.CommandLineUtils; using Microsoft.Extensions.Configuration; @@ -90,21 +91,28 @@ CommandOption descriptionUrl // Cannot use ADAL since there's no support for ROPC in .NET Core var parameters = new Dictionary { - {"resource", resourceId }, - {"client_id", clientId }, - {"grant_type", "password" }, - {"username", username.Value() }, - {"password", clientSecret.Value() }, + {"resource", resourceId}, + {"client_id", clientId}, + {"grant_type", "password"}, + {"username", username.Value()}, + {"password", clientSecret.Value()}, }; using (var adalClient = new HttpClient()) { var result = await adalClient.PostAsync($"{authority}/oauth2/token", new FormUrlEncodedContent(parameters)); var res = await result.Content.ReadAsStringAsync(); - result.EnsureSuccessStatusCode(); - + var jObj = JObject.Parse(res); - var token = jObj["access_token"].Value(); + + if (!result.IsSuccessStatusCode) + { + var desc = jObj["error_description"].Value(); + throw new AuthenticationException(desc); + } + + var token = jObj["access_token"] + .Value(); return token; } } @@ -146,6 +154,11 @@ CommandOption descriptionUrl await str.CopyToAsync(fs); } } + catch (AuthenticationException e) + { + signCommandLineApplication.Error.WriteLine(e.Message); + return EXIT_CODES.FAILED; + } catch (Exception e) { signCommandLineApplication.Error.WriteLine("Exception: " + e); From fe65b08dc3e948e902adec53c67b11e7c5e0a819 Mon Sep 17 00:00:00 2001 From: Oren Novotny Date: Sun, 1 Jul 2018 14:35:29 -0400 Subject: [PATCH 2/2] only do prebuild --- .vsts.service.ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.vsts.service.ci.yml b/.vsts.service.ci.yml index 92e93d2f..820436f9 100644 --- a/.vsts.service.ci.yml +++ b/.vsts.service.ci.yml @@ -19,8 +19,10 @@ steps: - task: DotNetCoreCLI@2 displayName: Copy sdk files locally before build inputs: + command: custom projects: src/SignService/SignService.csproj - arguments: '-c $(BuildConfiguration) /t:PrebuildScript' + custom: msbuild + arguments: '/p:Configuration=$(BuildConfiguration) /t:PrebuildScript' - task: DotNetCoreCLI@2 displayName: Build and Publish