Skip to content

Commit 3c67ae7

Browse files
committed
update documentation issue #10
1 parent 5f2491b commit 3c67ae7

11 files changed

Lines changed: 190 additions & 134 deletions

File tree

README.md

Lines changed: 16 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,33 @@
1-
# CometD .NET Core implementation of Salesforce Platform events
1+
# CometD.NetCore.Salesforce
22

33
[![Build status](https://ci.appveyor.com/api/projects/status/baalfhs6vvc38icc?svg=true)](https://ci.appveyor.com/project/kdcllc/cometd-netcore-salesforce)
4+
[![NuGet](https://img.shields.io/nuget/v/CometD.NetCore.Salesforce.svg)](https://www.nuget.org/packages?q=Bet.AspNetCore)
5+
[![MyGet](https://img.shields.io/myget/kdcllc/v/CometD.NetCore.Salesforce.svg?label=myget)](https://www.myget.org/F/kdcllc/api/v2)
46

57
This repo contains the CometD .NET Core implementation for Salesforce Platform events.
6-
8+
79
These events can be subscribed to and listened to by your custom `Event Listener`. The sample application of this library can be found [here](https://github.com/kdcllc/Bet.BuildingBlocks.SalesforceEventBus).
810

911
The solution contains the following:
1012

11-
1. `CometD.NetCore2.Salesforce` Project
13+
1. [`CometD.NetCore2.Salesforce`](./src/CometD.NetCore.Salesforce/README.md)
1214
- A Salesforce Platform Events implementation based [Even Bus idea of eShopOnContainers](https://github.com/dotnet-architecture/eShopOnContainers).
1315
- [Reusable Building Blocks and sample application that listens to Salesforce push events](https://github.com/kdcllc/Bet.BuildingBlocks.SalesforceEventBus).
1416

15-
2. DotNet Cli tool `salesforce` Project
16-
- 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)
17-
18-
## Installation
19-
20-
- To include this library inside of your project run nuget package installation
21-
22-
```cmd
23-
PM> Install-Package CometD.NetCore2.Salesforce
24-
```
25-
26-
Or
27-
28-
```cmd
29-
dotnet add package CometD.NetCore.Salesforce
30-
```
31-
32-
- To Install Salesforce Cli tool globally run the following command:
33-
34-
```cmd
35-
dotnet tool install salesforce -g
36-
37-
```
38-
39-
To verify the installation run:
40-
41-
```cmd
42-
dotnet tool list -g
43-
```
44-
45-
## Usage of Salesforce dotnet cli tool
46-
47-
There are several ways to run this cli tool.
48-
49-
1. From any location with Consumer Key and Secret provided
17+
2. [DotNet Cli tool `salesforce`](./src/AuthApp/README.md)
18+
- This dotnet cli tool allows for retrieval of `Access` or `Refresh Tokens` to be used by any other application.
19+
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)
5020

51-
```bash
52-
salesforce get-tokens --key:{key} --secret:{secret} --login:https://login.salesforce.com --verbose:information
53-
```
54-
55-
2. Running the tool in the directory that contains `appsettings.json` file
56-
57-
```bash
58-
salesforce get-tokens --section Salesforce
59-
```
60-
Note: required configurations are as follows:
61-
62-
```json
63-
"Salesforce": {
64-
"ClientId": "",
65-
"ClientSecret": "",
66-
"LoginUrl": ""
67-
}
68-
````
69-
70-
3. Running with Azure Vault
71-
72-
`appsettings.json
73-
```json
74-
"AzureVault": {
75-
"BaseUrl": "https://{name}.vault.azure.net/"
76-
},
77-
```
78-
79-
Then run:
80-
81-
```cmd
82-
salesforce get-tokens --verbose:debug
83-
```
84-
85-
Or specify url within the dotnet cli tool like so:
86-
87-
```cmd
88-
salesforce get-tokens --azure https://{name}.vault.azure.net/"
89-
```
21+
## Saleforce Setup
9022

91-
This tool will open web browser and will require you to log in with your credentials to Salesforce portal in order to retrieve the tokens.
23+
[Watch Video](https://www.youtube.com/watch?v=L6OWyCfQD6U)
9224

93-
## Saleforce Setup
94-
[Video](https://www.youtube.com/watch?v=L6OWyCfQD6U)
9525
1. Sing up for development sandbox with Saleforce: [https://developer.salesforce.com/signup](https://developer.salesforce.com/signup).
9626
2. Create Connected App in Salesforce.
9727
3. Create a Platform Event.
9828

9929
### Create Connected App in Salesforce
30+
10031
1. Setup -> Quick Find -> manage -> App Manager -> New Connected App.
10132
2. Basic Info:
10233

@@ -120,13 +51,16 @@ This tool will open web browser and will require you to log in with your credent
12051

12152
Use workbench to test the Event [workbench](https://workbench.developerforce.com/login.php?startUrl=%2Finsert.php)
12253
## AuthApp
54+
12355
[Use login instead of test](https://github.com/developerforce/Force.com-Toolkit-for-NET/wiki/Web-Server-OAuth-Flow-Sample#am-i-using-the-test-environment)
12456
Simple application that provides with Web Server OAuth Authentication Flow to retrieve
12557
`Access Token` and `Refresh Token` to be used within the application.
12658

127-
## Special thanks to the following projects and contributors:
59+
## Special thanks to
60+
12861
- [Oyatel/CometD.NET](https://github.com/Oyatel/CometD.NET)
12962
- [nthachus/CometD.NET](https://github.com/nthachus/CometD.NET)
13063
- [tdawgy/CometD.NetCore](https://github.com/tdawgy/CometD.NetCore)
13164
- [eShopOnContainers](https://github.com/dotnet-architecture/eShopOnContainers)
132-
- [Chris Woolum](https://github.com/cwoolum)
65+
- [cwoolum](https://github.com/cwoolum)
66+
- [ts46235](https://github.com/ts46235)

src/AuthApp/AuthApp.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFrameworks>netcoreapp2.2;</TargetFrameworks>
6+
<Nullable>enable</Nullable>
67
<ToolCommandName>salesforce</ToolCommandName>
78
<PackageId>salesforce</PackageId>
8-
<Description>A command-line tool that enables Salesforce Access and Refresh Tokens Generation.</Description>
99
<PackAsTool>True</PackAsTool>
1010
</PropertyGroup>
1111

12+
<PropertyGroup>
13+
<Description>A command-line tool that enables Salesforce Access and Refresh Tokens Generation.</Description>
14+
<PackageTags>Salesforce refresh tokens, Salesforce access tokens, DotNetCore, AspNetCore, salesforce, OAuth Authentication Flow</PackageTags>
15+
</PropertyGroup>
16+
1217
<ItemGroup>
1318
<PackageReference Include="Bet.Extensions.AzureVault" />
1419
<PackageReference Include="Bet.Extensions.Hosting" />

src/AuthApp/HostBuilderExtensions.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,19 @@ internal static IHostBuilder CreateDefaultBuilder(HostBuilderOptions options)
5555
// configure Azure Vault from the other settings.
5656
var appAzureVaultUrl = config.Build().Bind<AzureVaultOptions>("AzureVault", enableValidation: false);
5757

58+
var inputValues = new Dictionary<string, string>
59+
{
60+
{ $"{options.SectionName}:ClientId", options?.Settings?.ClientId ?? string.Empty },
61+
{ $"{options.SectionName}:ClientSecret", options?.Settings?.ClientSecret ?? string.Empty },
62+
{ $"{options.SectionName}:LoginUrl", options?.Settings?.LoginUrl ?? string.Empty },
63+
{ $"{options.SectionName}:OAuthUri", options?.Settings?.OAuthUri ?? string.Empty },
64+
{ $"{options.SectionName}:OAuthorizeUri", options?.Settings?.OAuthorizeUri ?? string.Empty },
65+
};
66+
67+
config.AddInMemoryCollection(inputValues);
68+
5869
// build azure key vault from passed in parameter
59-
if (!string.IsNullOrWhiteSpace(options.AzureVault))
70+
if (!string.IsNullOrWhiteSpace(options?.AzureVault))
6071
{
6172
var dic = new Dictionary<string, string>
6273
{
@@ -68,26 +79,11 @@ internal static IHostBuilder CreateDefaultBuilder(HostBuilderOptions options)
6879

6980
// use appsettings vault information
7081
if (!string.IsNullOrWhiteSpace(appAzureVaultUrl.BaseUrl)
71-
|| !string.IsNullOrWhiteSpace(options.AzureVault))
82+
|| !string.IsNullOrWhiteSpace(options?.AzureVault))
7283
{
7384
config.AddAzureKeyVault(hostingEnviromentName: options.HostingEnviroment, options.UseAzureKeyPrefix);
7485
}
7586

76-
if (!string.IsNullOrWhiteSpace(options.Settings.ClientId)
77-
&& !string.IsNullOrWhiteSpace(options.Settings.ClientSecret))
78-
{
79-
var inputValues = new Dictionary<string, string>
80-
{
81-
{ $"{options.SectionName}:ClientId", options.Settings.ClientId },
82-
{ $"{options.SectionName}:ClientSecret", options.Settings.ClientSecret },
83-
{ $"{options.SectionName}:LoginUrl", options.Settings.LoginUrl },
84-
{ $"{options.SectionName}:OAuthUri", options.Settings.OAuthUri },
85-
{ $"{options.SectionName}:OAuthorizeUri", options.Settings.OAuthorizeUri },
86-
};
87-
88-
config.AddInMemoryCollection(inputValues);
89-
}
90-
9187
if ((options.Verbose && options.Level == LogLevel.Debug)
9288
|| options.Level == LogLevel.Trace)
9389
{

src/AuthApp/HostBuilderOptions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using AuthApp.Host;
1+
using AuthApp.Internal;
22

33
using Microsoft.Extensions.Logging;
44

@@ -9,7 +9,7 @@ internal class HostBuilderOptions
99
/// <summary>
1010
/// Sets Configuration file besides appsettings.json.
1111
/// </summary>
12-
public string ConfigFile { get; set; }
12+
public string? ConfigFile { get; set; }
1313

1414
/// <summary>
1515
/// Provides ability to get troubleshooting information.
@@ -29,7 +29,7 @@ internal class HostBuilderOptions
2929
/// <summary>
3030
/// Url for the azure key vault i.e. https://{vaultname}.vault.azure.net/.
3131
/// </summary>
32-
public string AzureVault { get; set; }
32+
public string? AzureVault { get; set; }
3333

3434
/// <summary>
3535
/// Prefix is based on Environment i.e. Development = dev, Production = prod.
@@ -39,16 +39,16 @@ internal class HostBuilderOptions
3939
/// <summary>
4040
/// Pass Hosting environment for the context of the application.
4141
/// </summary>
42-
public string HostingEnviroment { get; set; }
42+
public string HostingEnviroment { get; set; } = "Production";
4343

4444
/// <summary>
4545
/// Salesforce options.
4646
/// </summary>
47-
public SfConfig Settings { get; set; }
47+
public SfConfig? Settings { get; set; }
4848

4949
/// <summary>
5050
/// The name of the configuration section for the options.
5151
/// </summary>
52-
public string SectionName { get; set; }
52+
public string SectionName { get; set; } = "Salesforce";
5353
}
5454
}

src/AuthApp/Internal/Constants.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace AuthApp.Internal
2+
{
3+
internal static class Constants
4+
{
5+
public const string CLIToolName = "salesforce";
6+
}
7+
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
using Console = Colorful.Console;
1717

18-
namespace AuthApp.Host
18+
namespace AuthApp.Internal
1919
{
2020
/// <summary>
2121
/// Web Server OAuth Authentication Flow
@@ -40,6 +40,10 @@ public HttpServer(
4040

4141
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
4242
{
43+
Console.WriteLine();
44+
Console.WriteAscii("Token Generation Started...", Colorful.FigletFont.Default);
45+
Console.WriteLine();
46+
4347
if (_hostOptions.Verbose)
4448
{
4549
Console.WriteLine($"{nameof(HttpServer)} is starting.");
@@ -121,6 +125,9 @@ await auth.WebServerAsync(
121125
}
122126

123127
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
128+
129+
Console.WriteLine();
130+
Console.Write("Thanks for using this cli tool");
124131
}
125132
}
126133

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
using System.ComponentModel.DataAnnotations;
22

3-
namespace AuthApp.Host
3+
namespace AuthApp.Internal
44
{
5-
public class SfConfig
5+
internal class SfConfig
66
{
77
/// <summary>
88
/// Salesforce Client Id.
99
/// </summary>
1010
[Required]
11-
public string ClientId { get; set; }
11+
public string? ClientId { get; set; }
1212

1313
/// <summary>
1414
/// Salesforece Secret Id.
1515
/// </summary>
1616
[Required]
17-
public string ClientSecret { get; set; }
17+
public string? ClientSecret { get; set; }
1818

1919
/// <summary>
2020
/// i.e. https://login.salesforce.com.
2121
/// </summary>
2222
[Required]
2323
[Url]
24-
public string LoginUrl { get; set; }
24+
public string? LoginUrl { get; set; }
2525

2626
/// <summary>
2727
/// Default set to /services/oauth2/token.

src/AuthApp/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
using System.Reflection;
22
using System.Threading.Tasks;
33

4+
using AuthApp.Internal;
5+
46
using McMaster.Extensions.CommandLineUtils;
57

68
using Console = Colorful.Console;
79

810
namespace AuthApp
911
{
10-
[Command(Name = "salesforce", Description = "cli tool to help with salesforce development.")]
12+
[Command(Name = Constants.CLIToolName, Description = "cli tool to help with Salesforce development by providing with Refresh token generation.")]
1113
[Subcommand(typeof(TokenGeneratorCommand))]
1214
[HelpOption("-?")]
1315
[VersionOptionFromMember("--version", MemberName = nameof(GetVersion))]
@@ -25,8 +27,9 @@ private static string GetVersion()
2527

2628
private int OnExecute(CommandLineApplication app, IConsole console)
2729
{
28-
Console.WriteAscii("Salesforce", Colorful.FigletFont.Default);
30+
Console.WriteAscii(Constants.CLIToolName, Colorful.FigletFont.Default);
2931

32+
console.WriteLine();
3033
console.WriteLine("You must specify at a subcommand.");
3134
app.ShowHelp();
3235
return 1;

0 commit comments

Comments
 (0)