Created Testing the API (markdown)

Maxence Lange 2020-09-17 14:07:47 -01:00
Родитель 3a50b3944b
Коммит cf12f7d3c1
1 изменённых файлов: 61 добавлений и 0 удалений

61
Testing-the-API.md Normal file

@ -0,0 +1,61 @@
### Creating the App
This is the first request a 3rd party client would need to send:
```
curl -X POST https://your.nextcloud.com/index.php/apps/social/api/v1/apps \
-d "client_name=curl&redirect_uris=https://test.example.net/oauth/redirected&scopes=write+read&website=https://test.example.net"
```
should returns:
> ```
>{
> "id": 1,
> "name": "curl",
> "website": "https://test.example.net",
> "scopes": "write read",
> "client_id": "zahscLgi9rZp5SpiOuXGHoqZGAziMhlXVgmTM4Fl",
> "client_secret": "xcDAPQLISsAw4UKqrut1OarDuCXf3IzOJxXQesHs"
>}
> ```
### Authorize App, identify Account
Open a browser and go to the generated URL using `client_id`:
> https://your.nextcloud.com/index.php/apps/social/oauth/authorize?response_type=code&scope=write+read&redirect_uri=https://test.example.net/oauth/redirected&client_id=zahscLgi9rZp5SpiOuXGHoqZGAziMhlXVgmTM4Fl
After authentication, using the credentials of your Nextcloud account, you will be redirected to `https://test.example.net/oauth/redirected?code=VcIgHmSYPYrgrHyM8kRDxf4Gz-dJOuoNBuEz9mlZtw4`
### Obtain token
Once you have a `code`:
```
curl -X POST https://your.nextcloud.com/index.php/apps/social/oauth/token \
-d "client_id=zahscLgi9rZp5SpiOuXGHoqZGAziMhlXVgmTM4Fl&redirect_uri=https://test.example.net/oauth/redirected&client_secret=xcDAPQLISsAw4UKqrut1OarDuCXf3IzOJxXQesHs&grant_type=authorization_code&code=VcIgHmSYPYrgrHyM8kRDxf4Gz-dJOuoNBuEz9mlZtw4"
```
result will be:
> ```
>{
> "access_token": "7UnD7f1fbMUUGqRalX0cTSW5H-Ion40_at560DsvG1w",
> "token_type": "Bearer",
> "scope": "write read",
> "created_at": 1600354593
>}
> ```
### Navigating the API
The `access_token` will be needed to request the API: