Skip to content

Commit 5739d14

Browse files
Updating README to reflect new RestSharpV2 package
1 parent a145da9 commit 5739d14

File tree

1 file changed

+70
-5
lines changed

1 file changed

+70
-5
lines changed

README.md

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ Zero dependency library for generating a Mastercard API compliant OAuth signatur
2525
### Compatibility <a name="compatibility"></a>
2626

2727
#### .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.
28+
* Both the Core and RestSharp (deprecated) libraries require a .NET Framework implementing [.NET Standard](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) 1.3.
29+
* The RestSharp V2 library requires a .NET Framework implementing [.NET Standard](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) 2.0.
2930

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

47-
### Adding the Libraries to Your Project <a name="adding-the-libraries-to-your-project"></a>
48+
### Adding the Libraries to Your Project <a name="adding-the-libraries-to-your-project"></a>
4849

4950
#### Package Manager
51+
###### RestSharp
52+
```shell
53+
Install-Package Mastercard.Developer.OAuth1Signer.Core
54+
Install-Package Mastercard.Developer.OAuth1Signer.RestSharpV2
55+
```
56+
57+
###### RestSharp Portable (Deprecated)
5058
```shell
5159
Install-Package Mastercard.Developer.OAuth1Signer.Core
5260
Install-Package Mastercard.Developer.OAuth1Signer.RestSharp
5361
```
5462

5563
#### .NET CLI
64+
###### RestSharp
65+
```shell
66+
dotnet add package Mastercard.Developer.OAuth1Signer.Core
67+
dotnet add package Mastercard.Developer.OAuth1Signer.RestSharpV2
68+
```
69+
70+
###### RestSharp Portable (Deprecated)
5671
```shell
5772
dotnet add package Mastercard.Developer.OAuth1Signer.Core
5873
dotnet add package Mastercard.Developer.OAuth1Signer.RestSharp
@@ -90,7 +105,7 @@ These classes will modify the provided request object in-place and will add the
90105
Usage briefly described below, but you can also refer to the test project for examples.
91106

92107
+ [System.Net.Http.HttpClient](#system-net-http-httpclient)
93-
+ [RestSharp Portable](#restsharp-portable)
108+
+ [RestSharp](#restsharp)
94109

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

@@ -120,9 +135,14 @@ internal class RequestSignerHandler : HttpClientHandler
120135
}
121136
```
122137

123-
#### RestSharp Portable <a name="restsharp-portable"></a>
138+
#### RestSharp <a name="restsharp"></a>
139+
124140

125-
The `RestSharpSigner` class is located in the `Mastercard.Developer.OAuth1Signer.RestSharp` package.
141+
The `RestSharpSigner` class can be used with both the RestSharp, and RestSharp Portable packages.
142+
It can be found in the following locations:
143+
144+
* RestSharpV2 (RestSharp) location: `Mastercard.Developer.OAuth1Signer.RestSharpV2`
145+
* RestSharp (RestSharp Portable) location: `Mastercard.Developer.OAuth1Signer.RestSharp`
126146

127147
Usage:
128148
```cs
@@ -149,6 +169,7 @@ This project provides you with some authenticator classes you can use when confi
149169

150170
Generators currently supported:
151171
+ [csharp (targetFramework v5.0)](#csharp-generator-target-framework-v5)
172+
+ [csharp-netcore (targetFramework netcore2.0)](#csharp-netcore-generator-target-framework-netcore2.0)
152173

153174
#### csharp (targetFramework v5.0) <a name="csharp-generator-target-framework-v5"></a>
154175

@@ -178,3 +199,47 @@ config.ApiClient.RestClient.Authenticator = new RestSharpOAuth1Authenticator(Con
178199
var serviceApi = new ServiceApi(config);
179200
// ...
180201
```
202+
203+
#### csharp-netcore (targetFramework netcore2.0) <a name="csharp-netcore-generator-target-framework-netcore2.0"></a>
204+
205+
##### OpenAPI Generator
206+
207+
Client libraries can be generated using the following command:
208+
```shell
209+
java -jar openapi-generator-cli.jar generate -i openapi-spec.yaml -g csharp-netcore -c config.json -o out
210+
```
211+
config.json:
212+
```json
213+
{ "targetFramework": "netstandard2.0" }
214+
```
215+
216+
See also:
217+
* [CONFIG OPTIONS for csharp-netcore](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/csharp-netcore.md)
218+
219+
##### Usage of the `RestSharpSigner`
220+
221+
`RestSharpSigner` is located in the `Mastercard.Developer.OAuth1Signer.RestSharpV2` package.
222+
223+
##### Usage
224+
225+
Create a new file (for instance, `ApiClientInterceptor.cs`) extending the definition of the generated `ApiClient` class:
226+
227+
```cs
228+
partial class ApiClient
229+
{
230+
private const string ConsumerKey = "<Your-Consumer-Key>";
231+
private const string SigningKeyAlias = "<Your-Key-Alias>";
232+
private const string SigningKeyPassword = "<Your-Keystore-Password>";
233+
private const string SigningKeyPkcs12FilePath = "<path/to/your/p12>";
234+
private const string BaseServicePath = "https://api.mastercard.com/<service-path>";
235+
236+
partial void InterceptRequest(IRestRequest request)
237+
{
238+
var signingKey = AuthenticationUtils.LoadSigningKey(SigningKeyPkcs12FilePath, SigningKeyAlias, SigningKeyPassword, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
239+
var signer = new RestSharpSigner(ConsumerKey, signingKey);
240+
signer.Sign(new Uri(BaseServicePath), request);
241+
}
242+
}
243+
```
244+
245+

0 commit comments

Comments
 (0)