Skip to content

Commit ff57d35

Browse files
committed
resolves issue #4
1 parent d7c624c commit ff57d35

11 files changed

Lines changed: 80 additions & 27 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Or you can specify Azure Key Vault Url:
6363
Then run:
6464

6565
```cmd
66-
salesforce get-tokens
66+
salesforce get-tokens --verbose:debug
6767
```
6868

6969
Or specify url within the dotnet cli tool like so:

build/dependecies.props

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<Project>
22

33
<PropertyGroup>
4-
<NetCoreCommonVersion>2.1.1</NetCoreCommonVersion>
4+
<NetCoreCommonVersion>2.2.*</NetCoreCommonVersion>
5+
<BetCommonVersion>1.1.18</BetCommonVersion>
56
</PropertyGroup>
67

78
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1' Or '$(TargetFramework)' == 'netstandard2.0'">
@@ -13,7 +14,7 @@
1314
</PropertyGroup>
1415

1516
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
16-
<NetCoreCommonVersion>3.0.0-preview.19074.2</NetCoreCommonVersion>
17+
<NetCoreCommonVersion>3.0.0-preview*</NetCoreCommonVersion>
1718
</PropertyGroup>
1819

1920
<ItemGroup Label="NetCore">
@@ -39,13 +40,14 @@
3940
<PackageReference Update="Microsoft.AspNetCore.Http" Version="$(NetCoreCommonVersion)" />
4041
</ItemGroup>
4142

42-
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
43-
<PackageReference Update="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="3.0.0-preview-18571-0006" />
44-
<PackageReference Update="Microsoft.AspNetCore.Http" Version="3.0.0-preview-18571-0006" />
43+
<ItemGroup Label="Bet">
44+
<PackageReference Update="Bet.Extensions.Options" Version="$(BetCommonVersion)" />
45+
<PackageReference Update="Bet.Extensions.Hosting" Version="$(BetCommonVersion)" />
46+
<PackageReference Update="Bet.Extensions.AzureVault" Version="$(BetCommonVersion)"/>
47+
<PackageReference Update="Bet.Extensions.Logging" Version="$(BetCommonVersion)"/>
4548
</ItemGroup>
4649

4750
<ItemGroup Label="Shared Libraries">
48-
<PackageReference Update="Bet.AspNetCore" Version="1.0.3" />
4951
<PackageReference Update="CometD.NetCore2" Version="2.0.0" />
5052
<PackageReference Update="Bet.BuildingBlocks.SalesforceEventBus" Version="2.0.0" />
5153
<PackageReference Update="McMaster.Extensions.CommandLineUtils" Version="2.3.2"/>

build/settings.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<LangVersion>latest</LangVersion>
77
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
88
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
9-
<NoWarn>$(NoWarn);CS1591</NoWarn>
9+
<NoWarn>$(NoWarn);CS1591;IDE1006</NoWarn>
1010
</PropertyGroup>
1111

1212
<PropertyGroup Label="Nuget Package Settings">

src/AuthApp/AuthApp.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Bet.AspNetCore" />
13+
14+
<PackageReference Include="Bet.Extensions.Options" />
15+
<PackageReference Include="Bet.Extensions.Hosting" />
16+
<PackageReference Include="Bet.Extensions.AzureVault" />
17+
<PackageReference Include="Bet.Extensions.Logging" />
18+
1419
<PackageReference Include="Colorful.Console" />
1520
<PackageReference Include="McMaster.Extensions.CommandLineUtils" />
1621
<PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" />

src/AuthApp/Host/HttpServer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ await auth.WebServerAsync(
9494
_config.ClientSecret,
9595
redirectURI,
9696
code,
97-
$"{_config.LoginUrl}/services/oauth2/token");
98-
97+
$"{_config.LoginUrl}{_config.OAuthTokenUri}");
9998

10099
Console.WriteLineFormatted("Access_token = {0}",Color.Green, Color.Yellow, auth.AccessInfo.AccessToken);
101100
Console.WriteLineFormatted("Refresh_token = {0}", Color.Green, Color.Yellow, auth.AccessInfo.RefreshToken);
@@ -123,7 +122,7 @@ private int GetRandomUnusedPort()
123122

124123
private string GetAuthorizationUrl(string redirectURI)
125124
{
126-
var authEndpoint = $"{_config.LoginUrl}/services/oauth2/authorize";
125+
var authEndpoint = $"{_config.LoginUrl}{_config.OAuthUri}";
127126
var url = $"{authEndpoint}?response_type=code&access_type=offline&scope=openid%20profile%20api%20refresh_token%20offline_access&redirect_uri={Uri.EscapeDataString(redirectURI)}&client_id={_config.ClientId}";
128127
return url;
129128
}

src/AuthApp/Host/SfConfig.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,12 @@ public class SfConfig
2222
[Required]
2323
[Url]
2424
public string LoginUrl { get; set; }
25+
26+
/// <summary>
27+
/// Default set to /services/oauth2/token.
28+
/// </summary>
29+
public string OAuthTokenUri { get; set; } = "/services/oauth2/token";
30+
31+
public string OAuthUri { get; set; } = "/services/oauth2/authorize";
2532
}
2633
}

src/AuthApp/HostBuilderExtensions.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.Hosting;
66
using Microsoft.Extensions.Logging;
7-
using System;
87
using System.Collections.Generic;
98
using System.Drawing;
109
using System.IO;
@@ -30,13 +29,13 @@ internal static IHostBuilder CreateDefaultBuilder(HostBuilderOptions options)
3029

3130
var defaultConfigName = !string.IsNullOrWhiteSpace(options.ConfigFile) ? Path.GetFileName(options.ConfigFile) : "appsettings.json";
3231

33-
3432
if (options.Verbose)
3533
{
3634
Console.WriteLine($"ContentRoot:{fullPath}", color: Color.Green);
3735
}
3836

3937
builder
38+
.UseStartupFilter()
4039
.ConfigureAppConfiguration((context, config) =>
4140
{
4241
// appsettings file or others
@@ -70,7 +69,8 @@ internal static IHostBuilder CreateDefaultBuilder(HostBuilderOptions options)
7069
config.AddAzureKeyVault(hostingEnviromentName:options.HostingEnviroment, options.UseAzureKeyPrefix);
7170
}
7271

73-
if (options.Verbose)
72+
if (options.Verbose && options.Level == LogLevel.Debug
73+
|| options.Level == LogLevel.Trace)
7474
{
7575
config.Build().DebugConfigurations();
7676
}
@@ -98,7 +98,10 @@ internal static IHostBuilder CreateDefaultBuilder(HostBuilderOptions options)
9898

9999
if (options.Verbose)
100100
{
101-
services.AddLogging(x => x.AddFilter((_) => true));
101+
services.AddLogging(x => x.AddFilter((loglevel) =>
102+
{
103+
return loglevel == options.Level;
104+
}));
102105
}
103106

104107
services.AddSingleton(PhysicalConsole.Singleton);

src/AuthApp/HostBuilderOptions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace AuthApp
1+
using Microsoft.Extensions.Logging;
2+
3+
namespace AuthApp
24
{
35
internal class HostBuilderOptions
46
{
@@ -12,6 +14,11 @@ internal class HostBuilderOptions
1214
/// </summary>
1315
public bool Verbose { get; set; }
1416

17+
/// <summary>
18+
/// TraceLevel if verbose is present.
19+
/// </summary>
20+
public LogLevel Level { get; set; }
21+
1522
/// <summary>
1623
/// Ability to use Web project secrets.
1724
/// </summary>

src/AuthApp/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Reflection;
1+
using System;
2+
using System.Drawing;
3+
using System.Reflection;
24
using System.Threading.Tasks;
35
using McMaster.Extensions.CommandLineUtils;
46
using Console = Colorful.Console;
@@ -13,7 +15,8 @@ public class Program
1315
{
1416
private static Task<int> Main(string[] args)
1517
{
16-
return CommandLineApplication.ExecuteAsync<Program>(args);
18+
19+
return CommandLineApplication.ExecuteAsync<Program>(args);
1720
}
1821

1922
private int OnExecute(CommandLineApplication app, IConsole console)

src/AuthApp/Properties/launchSettings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"profiles": {
33
"AuthApp": {
44
"commandName": "Project",
5-
"commandLineArgs": "refresh-token --azure https://{name}.vault.azure.net/"
5+
//"commandLineArgs": "get-tokens --azure https://{name}.vault.azure.net/"
6+
"commandLineArgs": "get-tokens --verbose:information --section:sfconfig"
7+
68
}
79
}
810
}

0 commit comments

Comments
 (0)