Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !7437

[csharp-netcore]Http signing for csharp-netcore sdk

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/Ghufz/HTTPSigning_For_CSharpSDK into master 4 years ago
  • Overview 0
  • Commits 7
  • Pipelines 0
  • Changes 15

Created by: Ghufz

Implemented the HTTPSigning Auth for CSharp SDK. It provides RSA Key support and ECDSA key support (for ECDSA key support it require dotnetcore3 and above)

Example to configure HTTPSigning configuration

Configuration config = new Configuration();
config.BasePath = "https://xyz.com";

HTTPSigningConfiguration httpSigning = new HTTPSigningConfiguration()
{
	KeyId = "xxxxxxx6876789ac747/5ee09xxxx4612d31a62c01/5ee09a1d7564612d31a6xxxx",
	KeyFilePath = "C:\\SecretKey.txt",
	HTTPSigningHeader = new List<string>() { "(request-target)", "Host", "Date", "Digest" }
};

config.HTTPSigningConfiguration = httpSigning;

//After create the instance of API and pass the configuration object.
//call the required method on Api instance to accomplished the task.

var apiInstance = new PetApi(config);
var result = apiInstance.GetPetById("223333");

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language. @wing328
Compare
  • master (base)

and
  • latest version
    6402ec1f
    7 commits, 2 years ago

15 files
+ 2380
- 3

    Preferences

    File browser
    Compare changes
modules/openapi-g‎enerator/src/main‎
java/org/openapitoo‎ls/codegen/languages‎
CSharpNetCoreCl‎ientCodegen.java‎ +1 -0
resources/cs‎harp-netcore‎
Configurati‎on.mustache‎ +15 -1
HTTPSigningConfi‎guration.mustache‎ +711 -0
IReadableConfig‎uration.mustache‎ +5 -0
api.mu‎stache‎ +34 -0
samples/client/pets‎tore/csharp-netcore‎
OpenAP‎IClient‎
.openapi-‎generator‎
FI‎LES‎ +1 -0
src/Org.Op‎enAPITools‎
A‎pi‎
FakeA‎pi.cs‎ +30 -0
Cli‎ent‎
Configur‎ation.cs‎ +15 -1
HTTPSigningCo‎nfiguration.cs‎ +711 -0
IReadableCon‎figuration.cs‎ +5 -0
OpenAPIC‎lientCore‎
.openapi-‎generator‎
FI‎LES‎ +1 -0
src/Org.Op‎enAPITools‎
A‎pi‎
PetA‎pi.cs‎ +120 -0
Cli‎ent‎
Configur‎ation.cs‎ +15 -1
HTTPSigningCo‎nfiguration.cs‎ +711 -0
IReadableCon‎figuration.cs‎ +5 -0
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java
+ 1
- 0
  • View file @ 6402ec1f

  • Edit in single-file editor

  • Open in Web IDE


@@ -610,6 +610,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
@@ -610,6 +610,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
supportingFiles.add(new SupportingFile("OpenAPIDateConverter.mustache", clientPackageDir, "OpenAPIDateConverter.cs"));
supportingFiles.add(new SupportingFile("OpenAPIDateConverter.mustache", clientPackageDir, "OpenAPIDateConverter.cs"));
supportingFiles.add(new SupportingFile("ClientUtils.mustache", clientPackageDir, "ClientUtils.cs"));
supportingFiles.add(new SupportingFile("ClientUtils.mustache", clientPackageDir, "ClientUtils.cs"));
supportingFiles.add(new SupportingFile("HttpMethod.mustache", clientPackageDir, "HttpMethod.cs"));
supportingFiles.add(new SupportingFile("HttpMethod.mustache", clientPackageDir, "HttpMethod.cs"));
 
supportingFiles.add(new SupportingFile("HTTPSigningConfiguration.mustache",clientPackageDir,"HTTPSigningConfiguration.cs"));
if (supportsAsync) {
if (supportsAsync) {
supportingFiles.add(new SupportingFile("IAsynchronousClient.mustache", clientPackageDir, "IAsynchronousClient.cs"));
supportingFiles.add(new SupportingFile("IAsynchronousClient.mustache", clientPackageDir, "IAsynchronousClient.cs"));
}
}
modules/openapi-generator/src/main/resources/csharp-netcore/Configuration.mustache
+ 15
- 1
  • View file @ 6402ec1f

  • Edit in single-file editor

  • Open in Web IDE


@@ -83,6 +83,10 @@ namespace {{packageName}}.Client
@@ -83,6 +83,10 @@ namespace {{packageName}}.Client
private string _dateTimeFormat = ISO8601_DATETIME_FORMAT;
private string _dateTimeFormat = ISO8601_DATETIME_FORMAT;
private string _tempFolderPath = Path.GetTempPath();
private string _tempFolderPath = Path.GetTempPath();
 
/// <summary>
 
/// HTTPSigning configuration
 
/// </summary>
 
private HTTPSigningConfiguration _HTTPSigningConfiguration = null;
#endregion Private Members
#endregion Private Members
#region Constructors
#region Constructors
@@ -334,6 +338,15 @@ namespace {{packageName}}.Client
@@ -334,6 +338,15 @@ namespace {{packageName}}.Client
}
}
}
}
 
/// <summary>
 
/// Gets and Sets the HTTPSigningConfiuration
 
/// </summary>
 
public HTTPSigningConfiguration HTTPSigningConfiguration
 
{
 
get { return _HTTPSigningConfiguration; }
 
set { _HTTPSigningConfiguration = value; }
 
}
 
#endregion Properties
#endregion Properties
#region Methods
#region Methods
@@ -411,7 +424,8 @@ namespace {{packageName}}.Client
@@ -411,7 +424,8 @@ namespace {{packageName}}.Client
Password = second.Password ?? first.Password,
Password = second.Password ?? first.Password,
AccessToken = second.AccessToken ?? first.AccessToken,
AccessToken = second.AccessToken ?? first.AccessToken,
TempFolderPath = second.TempFolderPath ?? first.TempFolderPath,
TempFolderPath = second.TempFolderPath ?? first.TempFolderPath,
DateTimeFormat = second.DateTimeFormat ?? first.DateTimeFormat
DateTimeFormat = second.DateTimeFormat ?? first.DateTimeFormat,
 
HTTPSigningConfiguration = second.HTTPSigningConfiguration ?? first.HTTPSigningConfiguration
};
};
return config;
return config;
}
}
modules/openapi-generator/src/main/resources/csharp-netcore/HTTPSigningConfiguration.mustache 0 → 100644
+ 711
- 0
  • View file @ 6402ec1f

  • Edit in single-file editor

  • Open in Web IDE

Files with large changes are collapsed by default.

modules/openapi-generator/src/main/resources/csharp-netcore/IReadableConfiguration.mustache
+ 5
- 0
  • View file @ 6402ec1f

  • Edit in single-file editor

  • Open in Web IDE


@@ -96,5 +96,10 @@ namespace {{packageName}}.Client
@@ -96,5 +96,10 @@ namespace {{packageName}}.Client
/// </summary>
/// </summary>
/// <value>X509 Certificate collection.</value>
/// <value>X509 Certificate collection.</value>
X509CertificateCollection ClientCertificates { get; }
X509CertificateCollection ClientCertificates { get; }
 
 
/// <summary>
 
/// Gets the HTTPSigning configuration
 
/// </summary>
 
HTTPSigningConfiguration HTTPSigningConfiguration { get; }
}
}
}
}
 
\ No newline at end of file
modules/openapi-generator/src/main/resources/csharp-netcore/api.mustache
+ 34
- 0
  • View file @ 6402ec1f

  • Edit in single-file editor

  • Open in Web IDE


@@ -369,6 +369,23 @@ namespace {{packageName}}.{{apiPackage}}
@@ -369,6 +369,23 @@ namespace {{packageName}}.{{apiPackage}}
localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
}
}
{{/isOAuth}}
{{/isOAuth}}
 
{{#isHttpSignature}}
 
if(this.Configuration.HTTPSigningConfiguration != null)
 
{
 
var HttpSigningHeaders = this.Configuration.HTTPSigningConfiguration.GetHttpSignedHeader(this.Configuration.BasePath, "{{{httpMethod}}}", "{{{path}}}", localVarRequestOptions);
 
foreach (var headerItem in HttpSigningHeaders)
 
{
 
if (localVarRequestOptions.HeaderParameters.ContainsKey(headerItem.Key))
 
{
 
localVarRequestOptions.HeaderParameters[headerItem.Key] = new List<string>() { headerItem.Value };
 
}
 
else
 
{
 
localVarRequestOptions.HeaderParameters.Add(headerItem.Key, headerItem.Value);
 
}
 
}
 
}
 
{{/isHttpSignature}}
{{/authMethods}}
{{/authMethods}}
// make the HTTP request
// make the HTTP request
@@ -547,6 +564,23 @@ namespace {{packageName}}.{{apiPackage}}
@@ -547,6 +564,23 @@ namespace {{packageName}}.{{apiPackage}}
localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
}
}
{{/isOAuth}}
{{/isOAuth}}
 
{{#isHttpSignature}}
 
if(this.Configuration.HTTPSigningConfiguration != null)
 
{
 
var HttpSigningHeaders = this.Configuration.HTTPSigningConfiguration.GetHttpSignedHeader(this.Configuration.BasePath, "{{{httpMethod}}}", "{{{path}}}", localVarRequestOptions);
 
foreach (var headerItem in HttpSigningHeaders)
 
{
 
if (localVarRequestOptions.HeaderParameters.ContainsKey(headerItem.Key))
 
{
 
localVarRequestOptions.HeaderParameters[headerItem.Key] = new List<string>() { headerItem.Value };
 
}
 
else
 
{
 
localVarRequestOptions.HeaderParameters.Add(headerItem.Key, headerItem.Value);
 
}
 
}
 
}
 
{{/isHttpSignature}}
{{/authMethods}}
{{/authMethods}}
// make the HTTP request
// make the HTTP request
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
MathJax v2.7.4
MathJax v2.7.4
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference: mathjax/MathJax!1958
Source branch: github/fork/Ghufz/HTTPSigning_For_CSharpSDK

Menu

Explore Projects Groups Snippets