You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Creating the OAuth Authorization Header <aname="creating-the-oauth-authorization-header"></a>
55
+
The method that does all the heavy lifting is `OAuth().get_authorization_header`. 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.
import oauth1.authenticationutils as authenticationutils
68
-
import json
69
-
from urllib.parse import urlencode
70
-
```
73
+
Alternatively, you can use helper classes for some of the commonly used HTTP clients.
71
74
72
-
##### Get a signing key from the .p12 file (replace place-holder strings with values from your project in developer zone). <aname="loading-the-signing-key"></a>
These classes will modify the provided request object in-place and will add the correct `Authorization` header. Once instantiated with a consumer key and private key, these objects can be reused.
76
76
77
-
baseUrl ='https://sandbox.api.mastercard.com'# remove 'sandbox.' if calling production
78
-
```
77
+
Usage briefly described below, but you can also refer to the test project for examples.
79
78
79
+
+[Requests: HTTP for Humans™](#requests)
80
80
81
-
##### To send a GET with query parameters: <aname="creating-the-oauth-get"></a>
81
+
####Requests: HTTP for Humans™ <aname="requests"></a>
82
82
83
-
```python
84
-
queryMap = {
85
-
"Format": "XML", # change this to toggle between and XML or JSON response
86
-
"Details": "offers.easysavings",
87
-
"PageOffset": "0",
88
-
"PageLength": "5",
89
-
"Latitude": "38.53463",
90
-
"Longitude": "-90.286781"
91
-
}
92
-
uri = baseUrl +"/merchants/v1/merchant?"+ urlencode(queryMap)
You can sign request objects using the `OAuthSigner` class.
84
+
85
+
Usage:
86
+
```python
87
+
uri ="https://sandbox.api.mastercard.com/service"
88
+
request = Request()
89
+
request.method ="POST"
90
+
request.data ="..."
98
91
92
+
signer = OAuthSigner(consumer_key, signing_key)
93
+
request = signer.sign_request(uri, request)
99
94
```
100
95
96
+
### Integrating with OpenAPI Generator API Client Libraries <aname="integrating-with-openapi-generator-api-client-libraries"></a>
101
97
102
-
##### To send a POST to : <aname="creating-the-oauth-post"></a>
98
+
[OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) generates API client libraries from [OpenAPI Specs](https://github.com/OAI/OpenAPI-Specification).
99
+
It provides generators and library templates for supporting multiple languages and frameworks.
103
100
104
-
```python
105
-
uri = baseUrl +"/eop/offer/v1/search?Format=XML"# change this to toggle between and XML or JSON response
r = requests.post(uri, headers=headers, data=reqJson)
116
-
print(r.text)
117
-
```
101
+
This project provides you with classes you can use when configuring your API client. These classes will take care of adding the correct `Authorization` header before sending the request.
118
102
103
+
Generators currently supported:
104
+
+[python](#python)
119
105
106
+
#### python <aname="python"></a>
120
107
121
-
##### Complete snippet to use interceptors : <aname="using-interceptors"></a>
108
+
##### OpenAPI Generator
122
109
123
-
```python
110
+
Client libraries can be generated using the following command:
111
+
```shell
112
+
java -jar openapi-generator-cli.jar generate -i openapi-spec.yaml -g python -o out
0 commit comments