Skip to content

Commit de3792d

Browse files
committed
removed test app from this project and updated authapp to be dotnet cli tool
1 parent 36d37f5 commit de3792d

20 files changed

Lines changed: 119 additions & 487 deletions

CometD.NetCore.Salesforce.sln

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.28606.126
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CometD.NetCore.Salesforce", "src\CometD.NetCore.Salesforce\CometD.NetCore.Salesforce.csproj", "{CDF94744-1E4D-41D4-A3AC-C0D1AFA6FD40}"
7-
EndProject
86
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8031B188-9FF6-4932-90AC-98DD21AF4D13}"
97
ProjectSection(SolutionItems) = preProject
108
.editorconfig = .editorconfig
119
.gitignore = .gitignore
1210
appveyor.yml = appveyor.yml
11+
clean.sh = clean.sh
1312
Directory.Build.props = Directory.Build.props
13+
Directory.Build.targets = Directory.Build.targets
1414
LICENSE = LICENSE
1515
README.md = README.md
1616
EndProjectSection
1717
EndProject
18-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApp", "src\TestApp\TestApp.csproj", "{6FACF1B8-5D3D-48BF-B2A9-FA06E195D1B6}"
19-
EndProject
2018
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AuthApp", "src\AuthApp\AuthApp.csproj", "{0AC0A8E4-AF3E-4078-A472-0D2DC1392C00}"
2119
EndProject
2220
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{DF67E08B-61B2-46CD-B3B0-56F6BDC4313E}"
@@ -28,32 +26,29 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{DF67E08B
2826
EndProject
2927
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F0246231-B425-4C7A-BD19-EF4177AF48C0}"
3028
EndProject
29+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CometD.NetCore.Salesforce", "src\CometD.NetCore.Salesforce\CometD.NetCore.Salesforce.csproj", "{03FD9019-E9BC-4ADE-9BFF-F6FD459CD579}"
30+
EndProject
3131
Global
3232
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3333
Debug|Any CPU = Debug|Any CPU
3434
Release|Any CPU = Release|Any CPU
3535
EndGlobalSection
3636
GlobalSection(ProjectConfigurationPlatforms) = postSolution
37-
{CDF94744-1E4D-41D4-A3AC-C0D1AFA6FD40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38-
{CDF94744-1E4D-41D4-A3AC-C0D1AFA6FD40}.Debug|Any CPU.Build.0 = Debug|Any CPU
39-
{CDF94744-1E4D-41D4-A3AC-C0D1AFA6FD40}.Release|Any CPU.ActiveCfg = Release|Any CPU
40-
{CDF94744-1E4D-41D4-A3AC-C0D1AFA6FD40}.Release|Any CPU.Build.0 = Release|Any CPU
41-
{6FACF1B8-5D3D-48BF-B2A9-FA06E195D1B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42-
{6FACF1B8-5D3D-48BF-B2A9-FA06E195D1B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
43-
{6FACF1B8-5D3D-48BF-B2A9-FA06E195D1B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
44-
{6FACF1B8-5D3D-48BF-B2A9-FA06E195D1B6}.Release|Any CPU.Build.0 = Release|Any CPU
4537
{0AC0A8E4-AF3E-4078-A472-0D2DC1392C00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4638
{0AC0A8E4-AF3E-4078-A472-0D2DC1392C00}.Debug|Any CPU.Build.0 = Debug|Any CPU
4739
{0AC0A8E4-AF3E-4078-A472-0D2DC1392C00}.Release|Any CPU.ActiveCfg = Release|Any CPU
4840
{0AC0A8E4-AF3E-4078-A472-0D2DC1392C00}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{03FD9019-E9BC-4ADE-9BFF-F6FD459CD579}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{03FD9019-E9BC-4ADE-9BFF-F6FD459CD579}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{03FD9019-E9BC-4ADE-9BFF-F6FD459CD579}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{03FD9019-E9BC-4ADE-9BFF-F6FD459CD579}.Release|Any CPU.Build.0 = Release|Any CPU
4945
EndGlobalSection
5046
GlobalSection(SolutionProperties) = preSolution
5147
HideSolutionNode = FALSE
5248
EndGlobalSection
5349
GlobalSection(NestedProjects) = preSolution
54-
{CDF94744-1E4D-41D4-A3AC-C0D1AFA6FD40} = {F0246231-B425-4C7A-BD19-EF4177AF48C0}
55-
{6FACF1B8-5D3D-48BF-B2A9-FA06E195D1B6} = {F0246231-B425-4C7A-BD19-EF4177AF48C0}
5650
{0AC0A8E4-AF3E-4078-A472-0D2DC1392C00} = {F0246231-B425-4C7A-BD19-EF4177AF48C0}
51+
{03FD9019-E9BC-4ADE-9BFF-F6FD459CD579} = {F0246231-B425-4C7A-BD19-EF4177AF48C0}
5752
EndGlobalSection
5853
GlobalSection(ExtensibilityGlobals) = postSolution
5954
SolutionGuid = {800A565D-7D93-4523-AD7A-EFA4067997DC}

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# CometD .NET Core implementation of Salesforce Platform events
22
[![Build status](https://ci.appveyor.com/api/projects/status/baalfhs6vvc38icc?svg=true)](https://ci.appveyor.com/project/kdcllc/cometd-netcore-salesforce)
33

4-
This repo contains the CometD .NET Core implementation for Salesforce Platform events.
4+
This repo contains the CometD .NET Core implementation for Salesforce Platform events.
5+
These events can be subscribed to and listened to by your custom `Event Listener`.
6+
57
1. `CometD.NetCore2.Salesforce`
6-
- Salesforce Platform Events as Event Bus [eShopOnContainers](https://github.com/dotnet-architecture/eShopOnContainers)
7-
2. `AuthApp`
8-
- utility to retrieve `Access Token` and `Refresh Token` to be used by `TestApp`.
9-
3. `TestApp`
10-
- sample application to test the code.
8+
- Salesforce Platform Events as Event Bus [eShopOnContainers](https://github.com/dotnet-architecture/eShopOnContainers).
9+
- [Reusable Building Blocks and sample application that listens to Salesforce push events](https://github.com/kdcllc/Bet.BuildingBlocks.SalesforceEventBus).
10+
2. DotNet Cli tool `AuthApp`
11+
- This dotnet cli tool allows for retrieval of `Access Token` and `Refresh Token` to be used by any other application. Please refer to [How Are Apps Authenticated with the Web Server OAuth Authentication Flow](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_web_server_oauth_flow.htm)
12+
1113

1214
## Nuget Packages
1315
```

build/dependecies.props

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup Label="NetCore">
20-
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="$(NetCoreCommonVersion)" />
21-
<PackageReference Update="Microsoft.Extensions.Logging" Version="$(NetCoreCommonVersion)" />
22-
<PackageReference Update="Microsoft.Extensions.Logging.Configuration" Version="$(NetCoreCommonVersion)" />
2320
<PackageReference Update="Microsoft.Extensions.Logging.Console" Version="$(NetCoreCommonVersion)" />
2421
<PackageReference Update="Microsoft.Extensions.Logging.Debug" Version="$(NetCoreCommonVersion)" />
25-
<PackageReference Update="Microsoft.Extensions.ObjectPool" Version="$(NetCoreCommonVersion)" />
2622

2723
<PackageReference Update="Microsoft.Extensions.Configuration.Binder" Version="$(NetCoreCommonVersion)" />
28-
<PackageReference Update="Microsoft.Extensions.Configuration.CommandLine" Version="$(NetCoreCommonVersion)" />
2924
<PackageReference Update="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(NetCoreCommonVersion)" />
25+
<PackageReference Update="Microsoft.Extensions.Configuration.CommandLine" Version="$(NetCoreCommonVersion)" />
3026
<PackageReference Update="Microsoft.Extensions.Configuration.Json" Version="$(NetCoreCommonVersion)" />
3127
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="$(NetCoreCommonVersion)" />
3228

@@ -37,10 +33,6 @@
3733
<PackageReference Update="Microsoft.Extensions.Options" Version="$(NetCoreCommonVersion)" />
3834
<PackageReference Update="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="$(NetCoreCommonVersion)" />
3935
<PackageReference Update="Microsoft.AspNetCore.Http" Version="$(NetCoreCommonVersion)" />
40-
<PackageReference Update="Microsoft.Extensions.Configuration.CommandLine" Version="$(NetCoreCommonVersion)" />
41-
<PackageReference Update="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(NetCoreCommonVersion)" />
42-
<PackageReference Update="Microsoft.Extensions.Configuration.Json" Version="$(NetCoreCommonVersion)" />
43-
<PackageReference Update="Microsoft.Extensions.Hosting" Version="$(NetCoreCommonVersion)" />
4436
</ItemGroup>
4537

4638
<ItemGroup Label="Shared Libraries">

build/sources.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
$(RestoreSources);
88
https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;
99
https://api.nuget.org/v3/index.json;
10+
D:\Dev\Nuget;
1011
</RestoreSources>
1112
</PropertyGroup>
1213
</Project>

src/AuthApp/AuthApp.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<PackageReference Include="Microsoft.AspNetCore.Http" />
1818
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" />
1919
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
20-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
2120
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" />
2221
<PackageReference Include="Microsoft.Extensions.Hosting" />
2322
<PackageReference Include="NetCoreForce.Client" />

src/AuthApp/Host/CustomHost.cs

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/AuthApp/Host/HttpServer.cs

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Drawing;
23
using System.IO;
34
using System.Net;
45
using System.Net.Sockets;
@@ -7,45 +8,65 @@
78
using System.Threading.Tasks;
89
using Microsoft.Extensions.Hosting;
910
using NetCoreForce.Client;
11+
using Console = Colorful.Console;
1012

1113
namespace AuthApp.Host
1214
{
1315
/// <summary>
1416
/// Web Server OAuth Authentication Flow
1517
/// https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_web_server_oauth_flow.htm
1618
/// </summary>
17-
public class HttpServer : BackgroundService
19+
internal class HttpServer : BackgroundService
1820
{
21+
private readonly HostBuilderOptions _hostOptions;
1922
private readonly SfConfig _config;
23+
private readonly IApplicationLifetime _applicationLifetime;
2024
private bool isCompleted = false;
2125

22-
public HttpServer(SfConfig config)
26+
public HttpServer(
27+
HostBuilderOptions hostOptions,
28+
SfConfig config,
29+
IApplicationLifetime applicationLifetime)
2330
{
31+
_hostOptions = hostOptions;
2432
_config = config;
33+
_applicationLifetime = applicationLifetime;
2534
}
2635

2736
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
2837
{
29-
Console.WriteLine($"{nameof(HttpServer)} is starting.");
38+
if (_hostOptions.Verbose)
39+
{
40+
Console.WriteLine($"{nameof(HttpServer)} is starting.");
41+
}
42+
3043
var http = new HttpListener();
3144
var redirectURI = string.Format("http://{0}:{1}/", "localhost", GetRandomUnusedPort());
3245
http.Prefixes.Add(redirectURI);
3346
http.Start();
3447

3548
var authUrl = GetAuthorizationUrl(redirectURI);
36-
Console.WriteLine($"Opening a browser window with Url: {authUrl}");
49+
50+
if (_hostOptions.Verbose)
51+
{
52+
Console.WriteLine($"Opening a browser window with Url: {authUrl}", Color.Blue);
53+
}
3754

3855
var process = ConsoleHandler.OpenBrowser(authUrl);
3956
var context = await http.GetContextAsync();
4057

41-
while (!stoppingToken.IsCancellationRequested || isCompleted )
58+
while (!stoppingToken.IsCancellationRequested)
4259
{
4360
if (isCompleted)
4461
{
62+
_applicationLifetime.StopApplication();
4563
return;
4664
}
4765

48-
Console.WriteLine($"{nameof(HttpServer)} is running");
66+
if (_hostOptions.Verbose)
67+
{
68+
Console.WriteLine($"{nameof(HttpServer)} is running");
69+
}
4970

5071
if (context != null)
5172
{
@@ -55,35 +76,40 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
5576

5677
if (context.Request.QueryString.Get("error") != null)
5778
{
58-
Console.WriteLine(string.Format("OAuth authorization error: {0}.", context.Request.QueryString.Get("error")));
79+
Console.WriteLine($"OAuth authorization error: {context.Request.QueryString.Get("error")}.", Color.Red);
5980
}
6081
if (context.Request.QueryString.Get("code") == null)
6182
{
62-
Console.WriteLine("Malformed authorization response. " + context.Request.QueryString);
83+
Console.WriteLine($"Malformed authorization response {context.Request.QueryString}", Color.Red);
6384
}
6485

6586
// Authorization code the consumer must use to obtain the access and refresh tokens.
6687
// The authorization code expires after 15 minutes.
6788
var code = context.Request.QueryString.Get("code");
89+
Console.WriteLine($"The authorization code will expire in 15 minutes: {code}", Color.Blue);
6890

6991
var auth = new AuthenticationClient();
70-
await auth.WebServerAsync(_config.ClientId,
71-
_config.ClientSecret,
72-
redirectURI,
73-
code,
74-
$"{_config.LoginUrl}/services/oauth2/token");
92+
await auth.WebServerAsync(
93+
_config.ClientId,
94+
_config.ClientSecret,
95+
redirectURI,
96+
code,
97+
$"{_config.LoginUrl}/services/oauth2/token");
7598

7699

77-
Console.WriteLine($"Your access_token is {auth.AccessInfo.AccessToken}");
78-
Console.WriteLine($"Your refresh_token is {auth.AccessInfo.RefreshToken}");
100+
Console.WriteLineFormatted("Access_token = {0}",Color.Green, Color.Yellow, auth.AccessInfo.AccessToken);
101+
Console.WriteLineFormatted("Refresh_token = {0}", Color.Green, Color.Yellow, auth.AccessInfo.RefreshToken);
79102

80103
isCompleted = true;
104+
105+
http.Stop();
106+
if (_hostOptions.Verbose)
107+
{
108+
Console.WriteLine($"{nameof(HttpServer)} is stopping.");
109+
}
81110
}
82111
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
83112
}
84-
85-
http.Stop();
86-
Console.WriteLine($"{nameof(HttpServer)} is stopping.");
87113
}
88114

89115
private int GetRandomUnusedPort()

0 commit comments

Comments
 (0)