Skip to content

Commit

Permalink
Merge pull request #40 from onovotny/client-updates
Browse files Browse the repository at this point in the history
Add a better error message if it's a bad user/pass
  • Loading branch information
Oren Novotny authored Jul 1, 2018
2 parents d608cb7 + fe65b08 commit cc2fa75
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .vsts.service.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Directory.build.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="2.1.65" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-62925-02" PrivateAssets="All"/>
</ItemGroup>

</Project>
29 changes: 21 additions & 8 deletions src/SignClient/SignCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,21 +91,28 @@ CommandOption descriptionUrl
// Cannot use ADAL since there's no support for ROPC in .NET Core
var parameters = new Dictionary<string, string>
{
{"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<string>();
if (!result.IsSuccessStatusCode)
{
var desc = jObj["error_description"].Value<string>();
throw new AuthenticationException(desc);
}
var token = jObj["access_token"]
.Value<string>();
return token;
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cc2fa75

Please sign in to comment.