Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: salesforce-marketingcloud/FuelSDK-CSharp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.2.0
Choose a base ref
...
head repository: salesforce-marketingcloud/FuelSDK-CSharp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 6 commits
  • 11 files changed
  • 3 contributors

Commits on May 10, 2019

  1. Updated readme. (#76)

    sfdrogojan authored May 10, 2019
    Copy the full SHA
    9bf0a99 View commit details

Commits on May 15, 2019

  1. Adding Context Switching support for OAuth2

    Adding Context Switching support for OAuth2 authentication.
    manivinesh authored and sfdrogojan committed May 15, 2019
    Copy the full SHA
    38dde7c View commit details

Commits on May 30, 2019

  1. Update issue templates

    sfdrogojan authored May 30, 2019
    Copy the full SHA
    eb36a47 View commit details
  2. Update issue templates

    sfdrogojan authored May 30, 2019
    Copy the full SHA
    d647407 View commit details

Commits on Aug 6, 2019

  1. Refresh token public app support (#81)

    * Added RefreshToken,Webapp and public app support for oauth2
    
    * updated readme
    
    * address code review concerns
    
    * address code review concerns
    
    * address code review concerns
    
    * address code review concerns
    
    * address code review concerns
    
    * Small update in README.md
    
    * modified test name and added comments
    
    * updating version in code
    manivinesh authored Aug 6, 2019
    Copy the full SHA
    aebf1e0 View commit details

Commits on Oct 12, 2021

  1. Copy the full SHA
    526e163 View commit details
39 changes: 39 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Bug report
about: Describe the issue you found
title: "[BUG]"
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Code snippet**
A code snippet that demonstrates the issue or a link to a code repository the developers can easily pull down to recreate the issue locally.

Note: Because the developers need to copy and paste the code snippet, including a code snippet as a media file (e.g. gif) is not sufficient.


**Environment**
- SDK Version [e.g. 1.1.0]
- .NET Framework version

**The bug has the severity**
- [ ] Critical: The defect affects critical functionality or critical data. It does not have a workaround.
- [ ] Major: The defect affects major functionality or major data. It has a workaround but is not obvious and is difficult.
- [ ] Minor: The defect affects minor functionality or non-critical data. It has an easy workaround.
- [ ] Trivial: The defect does not affect functionality or data. It does not even need a workaround. It does not impact productivity or efficiency. It is merely an inconvenience.

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[Enhancement]"
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe**
A clear and concise description of what the problem is.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
2 changes: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Comment line immediately above ownership line is reserved for related gus information. Please be careful while editing.
#ECCN:Open Source
88 changes: 81 additions & 7 deletions FuelSDK-CSharp/ETClient.cs
Original file line number Diff line number Diff line change
@@ -20,13 +20,13 @@ namespace FuelSDK
/// </summary>
public class ETClient
{
public const string SDKVersion = "FuelSDK-C#-v1.2.0";
public const string SDKVersion = "FuelSDK-C#-v1.3.0";

private FuelSDKConfigurationSection configSection;
public string AuthToken { get; private set; }
public SoapClient SoapClient { get; private set; }
public string InternalAuthToken { get; private set; }
public string RefreshKey { get; private set; }
public string RefreshKey { get; internal set; }
public DateTime AuthTokenExpiration { get; private set; }
public JObject Jwt { get; private set; }
public string EnterpriseId { get; private set; }
@@ -102,9 +102,50 @@ public ETClient(NameValueCollection parameters = null, RefreshState refreshState
{
configSection.UseOAuth2Authentication = parameters["useOAuth2Authentication"];
}
if (parameters.AllKeys.Contains("accountId"))
{
configSection.AccountId = parameters["accountId"];
}
if (parameters.AllKeys.Contains("scope"))
{
configSection.Scope = parameters["scope"];
}
if (parameters.AllKeys.Contains("applicationType"))
{
configSection.ApplicationType = parameters["applicationType"];
}
if (parameters.AllKeys.Contains("authorizationCode"))
{
configSection.AuthorizationCode = parameters["authorizationCode"];
}
if (parameters.AllKeys.Contains("redirectURI"))
{
configSection.RedirectURI = parameters["redirectURI"];
}
}
if (string.IsNullOrEmpty(configSection.ClientId) || string.IsNullOrEmpty(configSection.ClientSecret))
throw new Exception("clientId or clientSecret is null: Must be provided in config file or passed when instantiating ETClient");

configSection.ApplicationType = string.IsNullOrEmpty(configSection.ApplicationType) ? "server" : configSection.ApplicationType;

if (configSection.ApplicationType.Equals("public") || configSection.ApplicationType.Equals("web"))
{
if (string.IsNullOrEmpty(configSection.AuthorizationCode) || string.IsNullOrEmpty(configSection.RedirectURI))
{
throw new Exception("AuthorizationCode or RedirectURI is null: For Public/Web Apps, AuthCode and Redirect URI must be provided in config file or passed when instantiating ETClient");
}
}

if (configSection.ApplicationType.Equals("public"))
{
if(string.IsNullOrEmpty(configSection.ClientId))
throw new Exception("clientId is null: Must be provided in config file or passed when instantiating ETClient");
}
else
{
if (string.IsNullOrEmpty(configSection.ClientId) || string.IsNullOrEmpty(configSection.ClientSecret))
{
throw new Exception("clientId or clientSecret is null: Must be provided in config file or passed when instantiating ETClient");
}
}

// If JWT URL Parameter Used
var organizationFind = false;
@@ -322,7 +363,38 @@ public void RefreshToken(bool force = false)
RefreshKey = parsedResponse["refreshToken"].Value<string>().Trim();
}

private void RefreshTokenWithOauth2(bool force = false)
internal dynamic CreatePayload(FuelSDKConfigurationSection config)
{
dynamic payload = new JObject();

payload.client_id = config.ClientId;

if (!config.ApplicationType.Equals("public"))
payload.client_secret = config.ClientSecret;

if (!string.IsNullOrEmpty(RefreshKey))
{
payload.grant_type = "refresh_token";
payload.refresh_token = RefreshKey;
}
else if (!config.ApplicationType.Equals("server"))
{
payload.grant_type = "authorization_code";
payload.code = config.AuthorizationCode;
payload.redirect_uri = config.RedirectURI;
}
else
payload.grant_type = "client_credentials";

if (!string.IsNullOrEmpty(config.AccountId))
payload.account_id = config.AccountId;
if (!string.IsNullOrEmpty(config.Scope))
payload.scope = config.Scope;

return payload;
}

internal void RefreshTokenWithOauth2(bool force = false)
{
// workaround to support TLS 1.2 in .NET 4.0
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
@@ -338,8 +410,8 @@ private void RefreshTokenWithOauth2(bool force = false)

using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
string json = string.Format("{{\"client_id\": \"{0}\", \"client_secret\": \"{1}\", \"grant_type\": \"client_credentials\"}}", configSection.ClientId, configSection.ClientSecret);
streamWriter.Write(json);
dynamic payload = CreatePayload(configSection);
streamWriter.Write(payload.ToString());
}

// Get the response
@@ -356,6 +428,8 @@ private void RefreshTokenWithOauth2(bool force = false)
AuthTokenExpiration = DateTime.Now.AddSeconds(int.Parse(parsedResponse["expires_in"].Value<string>().Trim()));
configSection.SoapEndPoint = parsedResponse["soap_instance_url"].Value<string>().Trim() + "service.asmx";
configSection.RestEndPoint = parsedResponse["rest_instance_url"].Value<string>().Trim();
if (parsedResponse["refresh_token"] != null)
RefreshKey = parsedResponse["refresh_token"].Value<string>().Trim();
}

public FuelReturn AddSubscribersToList(string emailAddress, string subscriberKey, IEnumerable<int> listIDs) { return ProcessAddSubscriberToList(emailAddress, subscriberKey, listIDs); }
1 change: 1 addition & 0 deletions FuelSDK-CSharp/FuelSDK-CSharp.csproj
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@
<AssemblyOriginatorKeyFile>FuelSDKKeyFile.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
58 changes: 57 additions & 1 deletion FuelSDK-CSharp/FuelSDKConfigurationSection.cs
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ public string ClientId
/// Gets or sets the client secret.
/// </summary>
/// <value>The client secret.</value>
[ConfigurationProperty("clientSecret", IsRequired = true)]
[ConfigurationProperty("clientSecret")]
public string ClientSecret
{
get { return (string)this["clientSecret"]; }
@@ -78,6 +78,62 @@ public string UseOAuth2Authentication
get { return (string)this["useOAuth2Authentication"]; }
set { this["useOAuth2Authentication"] = value; }
}

/// <summary>
/// Gets or sets the Account Id.
/// </summary>
/// <value>Authenticaton Mode</value>
[ConfigurationProperty("accountId", DefaultValue = "")]
public string AccountId
{
get { return (string)this["accountId"]; }
set { this["accountId"] = value; }
}
/// <summary>
/// Gets or sets the Authenticaton Mode.
/// </summary>
/// <value>Authenticaton Mode</value>
[ConfigurationProperty("scope", DefaultValue = "")]
public string Scope
{
get { return (string)this["scope"]; }
set { this["scope"] = value; }
}

/// <summary>
/// Gets or sets the Application Type.
/// </summary>
/// <value>Application Type</value>
[ConfigurationProperty("applicationType", DefaultValue = "server")]
public string ApplicationType
{
get { return (string)this["applicationType"]; }
set { this["applicationType"] = value; }
}

/// <summary>
/// Gets or sets the Authorization Code.
/// </summary>
/// <value>Authorization Code</value>
[ConfigurationProperty("authorizationCode", DefaultValue = "")]
public string AuthorizationCode
{
get { return (string)this["authorizationCode"]; }
set { this["authorizationCode"] = value; }
}

/// <summary>
/// Gets or sets the Redirect URL.
/// </summary>
/// <value>Authorization Code</value>
[ConfigurationProperty("redirectURI", DefaultValue = "")]
public string RedirectURI
{
get { return (string)this["redirectURI"]; }
set { this["redirectURI"] = value; }
}


/// <summary>
/// Clone this instance.
/// </summary>
1 change: 1 addition & 0 deletions FuelSDK-CSharp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -34,3 +34,4 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: InternalsVisibleTo("FuelSDK-Test")]
2 changes: 2 additions & 0 deletions FuelSDK-Test/FuelSDK.Test.csproj
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
@@ -61,6 +62,7 @@
<Compile Include="ETTriggeredSendDefinitionTest.cs" />
<Compile Include="ETUnsubEventTest.cs" />
<Compile Include="FuelSDKConfigurationSectionTest.cs" />
<Compile Include="RefreshTokenTest.cs" />
<Compile Include="StackKeyTest.cs" />
</ItemGroup>
<ItemGroup>
Loading