Skip to content

Commit

Permalink
feat: add oauth2 authentication method
Browse files Browse the repository at this point in the history
Signed-off-by: Marie JONES <14836007+marie-j@users.noreply.github.com>
  • Loading branch information
marie-j committed Jul 3, 2024
1 parent 37d588b commit 880852b
Show file tree
Hide file tree
Showing 10 changed files with 3,424 additions and 3,430 deletions.
5 changes: 2 additions & 3 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"eqnull" : true, // Tolerate use of `== null`.
"es5" : false, // Allow EcmaScript 5 syntax.
"esnext" : true, // Allow ES.next specific features such as `const` and `let`.
"esversion" : 8, // ES version to use.
"evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
Expand All @@ -72,8 +72,7 @@
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
"validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function.
"esnext" : true,
"validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function."

// == Environments ====================================================
//
Expand Down
58 changes: 40 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Node.js Wrapper for OVH APIs](https://ovh.github.io/node-ovh/img/logo.png)](https://ovh.github.io/node-ovh)
[![Node.js Wrapper for OVHcloud APIs](https://ovh.github.io/node-ovh/img/logo.png)](https://ovh.github.io/node-ovh)

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

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

## Example Usage

### Login as a user
### OAuth2

#### 1. Generate credentials

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)

#### 2. Create an OVHcloud API client

```js
var ovh = require('ovh')({
clientID: 'YOUR_CLIENT_ID'
clientSecret: 'YOUR_CLIENT_SECRET'
endpoint: 'ovh-eu',
});
```

Depending on the API you want to use, you may set the endpoint to:
* `ovh-eu` for OVHcloud Europe API
* `ovh-us` for OVHcloud US API
* `ovh-ca` for OVHcloud Canada API


### Application Key/ApplicationSecret

#### 1. Create an application

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

* [OVH Europe](https://eu.api.ovh.com/createApp/)
* [OVH US](https://api.us.ovhcloud.com/createApp/)
* [OVH North-America](https://ca.api.ovh.com/createApp/)
* [OVHcloud Europe](https://eu.api.ovh.com/createApp/)
* [OVHcloud US](https://api.us.ovhcloud.com/createApp/)
* [OVHcloud North-America](https://ca.api.ovh.com/createApp/)
* [SoYouStart Europe](https://eu.api.soyoustart.com/createApp/)
* [SoYouStart North-America](https://ca.api.soyoustart.com/createApp/)
* [Kimsufi Europe](https://eu.api.kimsufi.com/createApp/)
Expand All @@ -67,17 +89,17 @@ secret (AS)**.

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

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

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

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

* OVH Europe: ```ovh-eu``` (default)
* OVH US: ```ovh-us```
* OVH North-America: ```ovh-ca```
* OVHcloud Europe: ```ovh-eu``` (default)
* OVHcloud US: ```ovh-us```
* OVHcloud North-America: ```ovh-ca```
* SoYouStart Europe: ```soyoustart-eu```
* SoYouStart North-America: ```soyoustart-ca```
* Kimsufi Europe: ```kimsufi-eu```
Expand Down Expand Up @@ -132,17 +154,17 @@ You are now be able to play with the API. Look at the
You can browse the API schemas using the web consoles of the APIs:
* [OVH Europe](https://eu.api.ovh.com/console/)
* [OVH US](https://api.us.ovhcloud.com/console/)
* [OVH North-America](https://ca.api.ovh.com/console/)
* [OVHcloud Europe](https://eu.api.ovh.com/console/)
* [OVHcloud US](https://api.us.ovhcloud.com/console/)
* [OVHcloud North-America](https://ca.api.ovh.com/console/)
* [SoYouStart Europe](https://eu.api.soyoustart.com/console/)
* [SoYouStart North-America](https://ca.api.soyoustart.com/console/)
* [Kimsufi Europe](https://eu.api.kimsufi.com/console/)
* [Kimsufi North-America](https://ca.api.kimsufi.com/console/)
## Migration from 1.x.x to 2.x.x without Proxy support
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.
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.
In order to have the informations about the bill with id "0123".
+ Before in 1.x.x with Proxy:
Expand Down Expand Up @@ -193,7 +215,7 @@ npm install -d
npm test
```
Integration tests use the OVH /domain/zone API, the tokens can be created
Integration tests use the OVHcloud /domain/zone API, the tokens can be created
[here](https://api.ovh.com/createToken/).
```
Expand All @@ -212,22 +234,22 @@ available in the *gh-pages* branch.
## Supported APIs
### OVH Europe
### OVHcloud Europe
- **Documentation**: https://eu.api.ovh.com/
- **Community support**: api-subscribe@ml.ovh.net
- **Console**: https://eu.api.ovh.com/console
- **Create application credentials**: https://eu.api.ovh.com/createApp/
- **Create script credentials** (all keys at once): https://eu.api.ovh.com/createToken/
### OVH US
### OVHcloud US
- **Documentation**: https://api.us.ovhcloud.com/
- **Console**: https://api.us.ovhcloud.com/console/
- **Create application credentials**: https://api.us.ovhcloud.com/createApp/
- **Create script credentials** (all keys at once): https://api.us.ovhcloud.com/createToken/
### OVH North America
### OVHcloud North America
- **Documentation**: https://ca.api.ovh.com/
- **Community support**: api-subscribe@ml.ovh.net
Expand Down
9 changes: 6 additions & 3 deletions lib/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@
*/
module.exports = {
'ovh-eu': {
'host': 'eu.api.ovh.com'
'host': 'eu.api.ovh.com',
'tokenURL': 'https://www.ovh.com/auth/'
},
'ovh-us': {
'host': 'api.us.ovhcloud.com'
'host': 'api.us.ovhcloud.com',
'tokenURL': 'https://us.ovhcloud.com/auth/'
},
'ovh-ca': {
'host': 'ca.api.ovh.com'
'host': 'ca.api.ovh.com',
'tokenURL': 'https://ca.ovh.com/auth/'
},
'sys-eu': {
'host': 'eu.api.soyoustart.com'
Expand Down
60 changes: 0 additions & 60 deletions lib/handler-maker.js

This file was deleted.

Loading

0 comments on commit 880852b

Please sign in to comment.