Skip to content

Commit 54c3dbc

Browse files
authored
Merge pull request #10 from Mastercard/feature/netcore-support
Updating README to reflect the new RestSharpV2 package
2 parents 09eba14 + 08302f4 commit 54c3dbc

File tree

1 file changed

+67
-19
lines changed

1 file changed

+67
-19
lines changed

README.md

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
[![](https://sonarcloud.io/api/project_badges/measure?project=Mastercard_oauth1-signer-csharp&metric=alert_status)](https://sonarcloud.io/dashboard?id=Mastercard_oauth1-signer-csharp)
55
[![](https://github.com/Mastercard/oauth1-signer-csharp/workflows/broken%20links%3F/badge.svg)](https://github.com/Mastercard/oauth1-signer-csharp/actions?query=workflow%3A%22broken+links%3F%22)
66
[![](https://img.shields.io/nuget/v/Mastercard.Developer.OAuth1Signer.Core.svg?label=nuget%20|%20core)](https://www.nuget.org/packages/Mastercard.Developer.OAuth1Signer.Core/)
7-
[![](https://img.shields.io/nuget/v/Mastercard.Developer.OAuth1Signer.RestSharp.svg?label=nuget%20|%20restsharp)](https://www.nuget.org/packages/Mastercard.Developer.OAuth1Signer.RestSharp/)
7+
[![](https://img.shields.io/nuget/v/Mastercard.Developer.OAuth1Signer.RestSharp.svg?label=nuget%20|%20restsharp%20portable)](https://www.nuget.org/packages/Mastercard.Developer.OAuth1Signer.RestSharp/)
8+
[![](https://img.shields.io/nuget/v/Mastercard.Developer.OAuth1Signer.RestSharpV2.svg?label=nuget%20|%20restsharp)](https://www.nuget.org/packages/Mastercard.Developer.OAuth1Signer.RestSharpV2/)
89
[![](https://img.shields.io/badge/license-MIT-yellow.svg)](https://github.com/Mastercard/oauth1-signer-csharp/blob/master/LICENSE)
910

1011
## Table of Contents
@@ -20,12 +21,15 @@
2021
* [Integrating with OpenAPI Generator API Client Libraries](#integrating-with-openapi-generator-api-client-libraries)
2122

2223
## Overview <a name="overview"></a>
23-
Zero dependency library for generating a Mastercard API compliant OAuth signature.
24+
* `OAuth1Signer.Core` is a zero dependency library for generating a Mastercard API compliant OAuth signature
25+
* `OAuth1Signer.RestSharpV2` is an extension dedicated to [RestSharp](https://restsharp.dev/)
26+
* `OAuth1Signer.RestSharp` is an extension dedicated to [RestSharp Portable](https://github.com/FubarDevelopment/restsharp.portable) (project no longer maintained)
2427

2528
### Compatibility <a name="compatibility"></a>
2629

2730
#### .NET <a name="net"></a>
28-
This library requires a .NET Framework implementing [.NET Standard](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) 1.3.
31+
* `OAuth1Signer.Core` and `OAuth1Signer.RestSharp` require a .NET Framework implementing [.NET Standard](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) 1.3.
32+
* `OAuth1Signer.RestSharpV2` requires a .NET Framework implementing [.NET Standard](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) 2.0.
2933

3034
#### Strong Naming <a name="strong-naming"></a>
3135
Assemblies are strong-named as per [Strong naming and .NET libraries](https://docs.microsoft.com/en-us/dotnet/standard/library-guidance/strong-naming).
@@ -44,18 +48,15 @@ As part of this set up, you'll receive credentials for your app:
4448
* A consumer key (displayed on the Mastercard Developer Portal)
4549
* A private request signing key (matching the public certificate displayed on the Mastercard Developer Portal)
4650

47-
### Adding the Libraries to Your Project <a name="adding-the-libraries-to-your-project"></a>
48-
51+
### Adding the Libraries to Your Project <a name="adding-the-libraries-to-your-project"></a>
4952
#### Package Manager
5053
```shell
51-
Install-Package Mastercard.Developer.OAuth1Signer.Core
52-
Install-Package Mastercard.Developer.OAuth1Signer.RestSharp
54+
Install-Package Mastercard.Developer.OAuth1Signer.{Core|RestSharp|RestSharpV2}
5355
```
5456

5557
#### .NET CLI
5658
```shell
57-
dotnet add package Mastercard.Developer.OAuth1Signer.Core
58-
dotnet add package Mastercard.Developer.OAuth1Signer.RestSharp
59+
dotnet add package Mastercard.Developer.OAuth1Signer.{Core|RestSharp|RestSharpV2}
5960
```
6061

6162
### Loading the Signing Key <a name="loading-the-signing-key"></a>
@@ -69,7 +70,7 @@ var signingKey = AuthenticationUtils.LoadSigningKey(
6970
```
7071

7172
### Creating the OAuth Authorization Header <a name="creating-the-oauth-authorization-header"></a>
72-
The method that does all the heavy lifting is `OAuth.GetAuthorizationHeader`, in the `Mastercard.Developer.OAuth1Signer.Core` package.
73+
The method that does all the heavy lifting is `OAuth.GetAuthorizationHeader`, in the `OAuth1Signer.Core` package.
7374
You can call into it directly and as long as you provide the correct parameters, it will return a string that you can add into your request's `Authorization` header.
7475

7576
```cs
@@ -90,11 +91,11 @@ These classes will modify the provided request object in-place and will add the
9091
Usage briefly described below, but you can also refer to the test project for examples.
9192

9293
+ [System.Net.Http.HttpClient](#system-net-http-httpclient)
93-
+ [RestSharp Portable](#restsharp-portable)
94+
+ [RestSharp](#restsharp)
9495

9596
#### System.Net.Http.HttpClient <a name="system-net-http-httpclient"></a>
9697

97-
The `NetHttpClientSigner` class is located in the `Mastercard.Developer.OAuth1Signer.Core` package.
98+
The `NetHttpClientSigner` class is located in the `OAuth1Signer.Core` package.
9899

99100
Usage:
100101
```cs
@@ -120,9 +121,9 @@ internal class RequestSignerHandler : HttpClientHandler
120121
}
121122
```
122123

123-
#### RestSharp Portable <a name="restsharp-portable"></a>
124+
#### RestSharp <a name="restsharp"></a>
124125

125-
The `RestSharpSigner` class is located in the `Mastercard.Developer.OAuth1Signer.RestSharp` package.
126+
A `RestSharpSigner` class is provided for both RestSharp and RestSharp Portable. It can be found in the `OAuth1Signer.RestSharp` and `OAuth1Signer.RestSharpV2` packages.
126127

127128
Usage:
128129
```cs
@@ -148,28 +149,75 @@ It provides generators and library templates for supporting multiple languages a
148149
This project provides you with some authenticator classes you can use when configuring your API client. These classes will take care of adding the correct `Authorization` header before sending the request.
149150

150151
Generators currently supported:
151-
+ [csharp (targetFramework v5.0)](#csharp-generator-target-framework-v5)
152+
+ [csharp-netcore](#csharp-netcore-generator)
153+
+ [csharp (deprecated)](#csharp-generator)
154+
155+
156+
#### csharp-netcore<a name="csharp-netcore-generator-target-framework-netcore2.0"></a>
157+
158+
##### OpenAPI Generator
159+
160+
Client libraries can be generated using the following command:
161+
```shell
162+
openapi-generator-cli generate -i openapi-spec.yaml -g csharp-netcore -c config.json -o out
163+
```
164+
config.json:
165+
```json
166+
{ "targetFramework": "netstandard2.0" }
167+
```
168+
169+
See also:
170+
* [OpenAPI Generator (executable)](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-cli)
171+
* [CONFIG OPTIONS for csharp-netcore](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/csharp-netcore.md)
172+
173+
##### Usage of the `RestSharpSigner`
174+
175+
`RestSharpSigner` is located in the `OAuth1Signer.RestSharpV2` package.
176+
177+
##### Usage
152178

153-
#### csharp (targetFramework v5.0) <a name="csharp-generator-target-framework-v5"></a>
179+
Create a new file (for instance, `ApiClientInterceptor.cs`) extending the definition of the generated `ApiClient` class:
180+
181+
```cs
182+
partial class ApiClient
183+
{
184+
private const string ConsumerKey = "<Your-Consumer-Key>";
185+
private const string SigningKeyAlias = "<Your-Key-Alias>";
186+
private const string SigningKeyPassword = "<Your-Keystore-Password>";
187+
private const string SigningKeyPkcs12FilePath = "<path/to/your/p12>";
188+
private const string BaseServicePath = "https://api.mastercard.com/<service-path>";
189+
190+
partial void InterceptRequest(IRestRequest request)
191+
{
192+
var signingKey = AuthenticationUtils.LoadSigningKey(SigningKeyPkcs12FilePath, SigningKeyAlias, SigningKeyPassword, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
193+
var signer = new RestSharpSigner(ConsumerKey, signingKey);
194+
signer.Sign(new Uri(BaseServicePath), request);
195+
}
196+
}
197+
```
198+
199+
#### csharp (deprecated)<a name="csharp-generator"></a>
154200

155201
##### OpenAPI Generator
156202

157203
Client libraries can be generated using the following command:
158204
```shell
159-
java -jar openapi-generator-cli.jar generate -i openapi-spec.yaml -g csharp -c config.json -o out
205+
openapi-generator-cli generate -i openapi-spec.yaml -g csharp -c config.json -o out
160206
```
161207
config.json:
162208
```json
163-
{ "targetFramework": "v5.0" }
209+
{ "targetFramework": "netstandard1.3" }
164210
```
165211

212+
⚠️ `v5.0` was used for `targetFramework` in OpenAPI Generator versions prior 5.0.0.
213+
166214
See also:
167215
* [OpenAPI Generator (executable)](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-cli)
168216
* [CONFIG OPTIONS for csharp](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/csharp.md)
169217
170218
##### Usage of the `RestSharpOAuth1Authenticator`
171219

172-
`RestSharpOAuth1Authenticator` is located in the `Mastercard.Developer.OAuth1Signer.RestSharp` package.
220+
`RestSharpOAuth1Authenticator` is located in the `OAuth1Signer.RestSharp` package.
173221

174222
```cs
175223
var config = Configuration.Default;

0 commit comments

Comments
 (0)