Skip to content

Commit 2804155

Browse files
authored
Merge pull request #53 from ovh/oauth2
feat: add oauth2 authentication method
2 parents 37d588b + 880852b commit 2804155

10 files changed

+3424
-3430
lines changed

.jshintrc

+2-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
5454
"eqnull" : true, // Tolerate use of `== null`.
5555
"es5" : false, // Allow EcmaScript 5 syntax.
56-
"esnext" : true, // Allow ES.next specific features such as `const` and `let`.
56+
"esversion" : 8, // ES version to use.
5757
"evil" : false, // Tolerate use of `eval`.
5858
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
5959
"funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
@@ -72,8 +72,7 @@
7272
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
7373
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
7474
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
75-
"validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function.
76-
"esnext" : true,
75+
"validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function."
7776

7877
// == Environments ====================================================
7978
//

README.md

+40-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[![Node.js Wrapper for OVH APIs](https://ovh.github.io/node-ovh/img/logo.png)](https://ovh.github.io/node-ovh)
1+
[![Node.js Wrapper for OVHcloud APIs](https://ovh.github.io/node-ovh/img/logo.png)](https://ovh.github.io/node-ovh)
22

3-
The easiest way to use the [OVH.com](https://ovh.com) APIs in your [node.js](https://nodejs.org/) applications.
3+
The easiest way to use the [OVHcloud.com](https://www.ovhcloud.com) APIs in your [node.js](https://nodejs.org/) applications.
44

55
[![NPM Version](https://img.shields.io/npm/v/ovh.svg?style=flat)](https://www.npmjs.org/package/ovh)
66
[![Build Status](https://img.shields.io/travis/ovh/node-ovh.svg?style=flat)](https://travis-ci.org/ovh/node-ovh)
@@ -47,16 +47,38 @@ $ npm install git://github.com/ovh/node-ovh.git
4747

4848
## Example Usage
4949

50-
### Login as a user
50+
### OAuth2
51+
52+
#### 1. Generate credentials
53+
54+
Generate a valid pair of clientID/clientSecret following this [documentation](https://help.ovhcloud.com/csm/en-manage-service-account?id=kb_article_view&sysparm_article=KB0059343)
55+
56+
#### 2. Create an OVHcloud API client
57+
58+
```js
59+
var ovh = require('ovh')({
60+
clientID: 'YOUR_CLIENT_ID'
61+
clientSecret: 'YOUR_CLIENT_SECRET'
62+
endpoint: 'ovh-eu',
63+
});
64+
```
65+
66+
Depending on the API you want to use, you may set the endpoint to:
67+
* `ovh-eu` for OVHcloud Europe API
68+
* `ovh-us` for OVHcloud US API
69+
* `ovh-ca` for OVHcloud Canada API
70+
71+
72+
### Application Key/ApplicationSecret
5173

5274
#### 1. Create an application
5375

5476
Depending the API you plan to use, you need to create an application on the below
5577
websites:
5678

57-
* [OVH Europe](https://eu.api.ovh.com/createApp/)
58-
* [OVH US](https://api.us.ovhcloud.com/createApp/)
59-
* [OVH North-America](https://ca.api.ovh.com/createApp/)
79+
* [OVHcloud Europe](https://eu.api.ovh.com/createApp/)
80+
* [OVHcloud US](https://api.us.ovhcloud.com/createApp/)
81+
* [OVHcloud North-America](https://ca.api.ovh.com/createApp/)
6082
* [SoYouStart Europe](https://eu.api.soyoustart.com/createApp/)
6183
* [SoYouStart North-America](https://ca.api.soyoustart.com/createApp/)
6284
* [Kimsufi Europe](https://eu.api.kimsufi.com/createApp/)
@@ -67,17 +89,17 @@ secret (AS)**.
6789

6890
#### 2. Authorize your application to access to a customer account
6991

70-
To allow your application to access to a customer account using an OVH API,
92+
To allow your application to access to a customer account using an OVHcloud API,
7193
you need a **consumer key (CK)**.
7294

7395
Here is a sample code you can use to allow your application to access to a
7496
complete account.
7597

7698
Depending the API you want to use, you need to specify the below API endpoint:
7799

78-
* OVH Europe: ```ovh-eu``` (default)
79-
* OVH US: ```ovh-us```
80-
* OVH North-America: ```ovh-ca```
100+
* OVHcloud Europe: ```ovh-eu``` (default)
101+
* OVHcloud US: ```ovh-us```
102+
* OVHcloud North-America: ```ovh-ca```
81103
* SoYouStart Europe: ```soyoustart-eu```
82104
* SoYouStart North-America: ```soyoustart-ca```
83105
* Kimsufi Europe: ```kimsufi-eu```
@@ -132,17 +154,17 @@ You are now be able to play with the API. Look at the
132154
133155
You can browse the API schemas using the web consoles of the APIs:
134156
135-
* [OVH Europe](https://eu.api.ovh.com/console/)
136-
* [OVH US](https://api.us.ovhcloud.com/console/)
137-
* [OVH North-America](https://ca.api.ovh.com/console/)
157+
* [OVHcloud Europe](https://eu.api.ovh.com/console/)
158+
* [OVHcloud US](https://api.us.ovhcloud.com/console/)
159+
* [OVHcloud North-America](https://ca.api.ovh.com/console/)
138160
* [SoYouStart Europe](https://eu.api.soyoustart.com/console/)
139161
* [SoYouStart North-America](https://ca.api.soyoustart.com/console/)
140162
* [Kimsufi Europe](https://eu.api.kimsufi.com/console/)
141163
* [Kimsufi North-America](https://ca.api.kimsufi.com/console/)
142164
143165
## Migration from 1.x.x to 2.x.x without Proxy support
144166
145-
For example if you use the OVH Europe API, you'll have to check on https://eu.api.ovh.com/console/ the endpoints available for your feature.
167+
For example if you use the OVHcloud Europe API, you'll have to check on https://eu.api.ovh.com/console/ the endpoints available for your feature.
146168
147169
In order to have the informations about the bill with id "0123".
148170
+ Before in 1.x.x with Proxy:
@@ -193,7 +215,7 @@ npm install -d
193215
npm test
194216
```
195217
196-
Integration tests use the OVH /domain/zone API, the tokens can be created
218+
Integration tests use the OVHcloud /domain/zone API, the tokens can be created
197219
[here](https://api.ovh.com/createToken/).
198220
199221
```
@@ -212,22 +234,22 @@ available in the *gh-pages* branch.
212234
213235
## Supported APIs
214236
215-
### OVH Europe
237+
### OVHcloud Europe
216238
217239
- **Documentation**: https://eu.api.ovh.com/
218240
- **Community support**: [email protected]
219241
- **Console**: https://eu.api.ovh.com/console
220242
- **Create application credentials**: https://eu.api.ovh.com/createApp/
221243
- **Create script credentials** (all keys at once): https://eu.api.ovh.com/createToken/
222244
223-
### OVH US
245+
### OVHcloud US
224246
225247
- **Documentation**: https://api.us.ovhcloud.com/
226248
- **Console**: https://api.us.ovhcloud.com/console/
227249
- **Create application credentials**: https://api.us.ovhcloud.com/createApp/
228250
- **Create script credentials** (all keys at once): https://api.us.ovhcloud.com/createToken/
229251
230-
### OVH North America
252+
### OVHcloud North America
231253
232254
- **Documentation**: https://ca.api.ovh.com/
233255
- **Community support**: [email protected]

lib/endpoints.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@
3737
*/
3838
module.exports = {
3939
'ovh-eu': {
40-
'host': 'eu.api.ovh.com'
40+
'host': 'eu.api.ovh.com',
41+
'tokenURL': 'https://www.ovh.com/auth/'
4142
},
4243
'ovh-us': {
43-
'host': 'api.us.ovhcloud.com'
44+
'host': 'api.us.ovhcloud.com',
45+
'tokenURL': 'https://us.ovhcloud.com/auth/'
4446
},
4547
'ovh-ca': {
46-
'host': 'ca.api.ovh.com'
48+
'host': 'ca.api.ovh.com',
49+
'tokenURL': 'https://ca.ovh.com/auth/'
4750
},
4851
'sys-eu': {
4952
'host': 'eu.api.soyoustart.com'

lib/handler-maker.js

-60
This file was deleted.

0 commit comments

Comments
 (0)