Skip to content

Commit bf3d58d

Browse files
committed
Update Arduino en Account APIs
1 parent 5029b1c commit bf3d58d

File tree

5 files changed

+107
-14
lines changed

5 files changed

+107
-14
lines changed

_includes/current/arduino.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ sections:
1111
redirect_from:
1212
- /refactor/arduino/
1313
- /v2-preview/arduino/
14+
- /arduino/
1415
---
1516

1617
[Arduino](https://www.arduino.cc/en/Guide/Introduction) is an open-source electronics platform based on easy-to-use hardware and software. It's intended for anyone making interactive projects.

_includes/current/arduino/_api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Total airtime: 0.00 s
4141
See the [DeviceInfo](https://github.com/TheThingsNetwork/arduino-device-lib/blob/master/examples/DeviceInfo/DeviceInfo.ino) example.
4242

4343
## Method: onMessage
44-
Sets a function which will be called to process incoming messages.
44+
Sets a function which will be called to process incoming messages. You'll want to do this in your `setup()` function and then define a `void (*cb)(const byte* payload, size_t length, port_t port)` function somewhere else in your sketch.
4545

4646
```c
4747
void onMessage(void (*cb)(const byte* payload, size_t length, port_t port));
@@ -98,7 +98,7 @@ int8_t sendBytes(const byte* payload, size_t length, port_t port = 1, bool confi
9898
- `const byte* payload `: Bytes to send.
9999
- `size_t length`: The number of bytes. Use `sizeof(payload)` to get it.
100100
- `port_t port = 1`: The port to address. Defaults to `1`.
101-
- `bool confirm = false`: Whether to ask for confirmation. Defaults to `false`.
101+
- `bool confirm = false`: Whether to ask for confirmation. Defaults to `false`. If confirmation fails, the method will return error code `-10`.
102102

103103
Returns a success or error code and logs the related error message:
104104

@@ -134,4 +134,4 @@ bool provision(const char *appEui, const char *appKey);
134134
```
135135

136136
- `const char *appEui`: Application Identifier for the device.
137-
- `const char *appKey`: Application Key assigned to the device.
137+
- `const char *appKey`: Application Key assigned to the device.

_includes/draft/account/_api.md

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ to be able to run a TTN backend.
1010

1111
### Security
1212
---
13-
1413
|oauth2|*OAuth 2.0*|
1514
|---|---|
1615
|Flow|accessCode|
@@ -39,7 +38,6 @@ to be able to run a TTN backend.
3938

4039
### /applications
4140
---
42-
4341
##### ***GET***
4442
**Summary:** List applications.
4543

@@ -74,7 +72,6 @@ collaborator.
7472

7573
### /{app_id}
7674
---
77-
7875
##### ***GET***
7976
**Summary:** Get application.
8077

@@ -131,7 +128,6 @@ collaborator.
131128

132129
### /{app_id}/euis
133130
---
134-
135131
##### ***GET***
136132
**Summary:** List EUIs of an application.
137133

@@ -168,7 +164,6 @@ collaborator.
168164

169165
### /{app_id}/euis/{eui}
170166
---
171-
172167
##### ***PUT***
173168
**Summary:** Add an EUI to the application.
174169

@@ -207,7 +202,6 @@ collaborator.
207202

208203
### /{app_id}/collaborators
209204
---
210-
211205
##### ***GET***
212206
**Summary:** List the collaborators of the application.
213207

@@ -227,7 +221,6 @@ collaborator.
227221

228222
### /{app_id}/collaborators/{username}
229223
---
230-
231224
##### ***GET***
232225
**Summary:** Get a collaborators rights to the application.
233226

@@ -284,7 +277,6 @@ It is not possible to
284277

285278
### /{app_id}/rights
286279
---
287-
288280
##### ***GET***
289281
**Summary:** Get the rights you have to the specified application with the current authentication method.
290282

@@ -300,9 +292,54 @@ It is not possible to
300292
| ---- | ----------- |
301293
| 200 | The rights you have to the application. |
302294

303-
### /{app_id}/token
295+
### /{app_id}/access-keys
304296
---
297+
##### ***POST***
298+
**Summary:** Create a new access key with the specified name and rights
299+
300+
**Parameters**
305301

302+
| Name | Located in | Description | Required | Type |
303+
| ---- | ---------- | ----------- | -------- | ---- |
304+
| app_id | path | The ID of the application. | Yes | string |
305+
| token_exchange | body | The body of the request to create an access key | No | |
306+
307+
### /{app_id}/access-keys/{keyname}
308+
---
309+
##### ***GET***
310+
**Summary:** Get information about an app access key
311+
312+
**Parameters**
313+
314+
| Name | Located in | Description | Required | Type |
315+
| ---- | ---------- | ----------- | -------- | ---- |
316+
| app_id | path | The ID of the application. | Yes | string |
317+
| keyname | path | The name of the access key | Yes | string |
318+
319+
**Responses**
320+
321+
| Code | Description |
322+
| ---- | ----------- |
323+
| 200 | The resulting access key |
324+
325+
##### ***DELETE***
326+
**Summary:** Remove an access key
327+
328+
**Parameters**
329+
330+
| Name | Located in | Description | Required | Type |
331+
| ---- | ---------- | ----------- | -------- | ---- |
332+
| app_id | path | The ID of the application. | Yes | string |
333+
| keyname | path | The name of the access key | Yes | string |
334+
335+
**Responses**
336+
337+
| Code | Description |
338+
| ---- | ----------- |
339+
| 204 | The key was successfully removed |
340+
341+
### /{app_id}/token
342+
---
306343
##### ***POST***
307344
**Summary:** Exchange an application Access Key for an application Access Token.
308345

_includes/draft/account/_authentication.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ It works exactly like a standard OAuth 2.0 password flow. The client initiates a
253253
request:
254254

255255
```plaintext
256-
HTTP/1.1 GET /api/v2/applications/token
256+
HTTP/1.1 POST /api/v2/applications/token
257257
Content-Type: application/json
258258
Authorization: Basic <basic_auth>
259259
@@ -306,5 +306,57 @@ If the exchange fails for whatever reason, you will get a response like this:
306306
}
307307
```
308308

309+
# OAuth 2.0 Authorization flow
310+
311+
In this section we describe a sample `authorization_code` code flow.
312+
Assuming you have a registered client with these properties:
313+
314+
```
315+
client_id: foo-client
316+
client_secret: secret
317+
redirect_uri: http://www.example.com/oauth/callback
318+
scope: [ 'apps' ]
319+
```
320+
321+
## 1. Make an authorization request
322+
323+
To be able to use your client, a user will have to authorize it first on the
324+
account server. You can tell the user to do so by redirecting to:
325+
326+
```
327+
https://account.thethingsnetwork.org/users/authorize?client_id=foo-client&redirect_uri=http://www.example.com/oauth/callback&response_type=code
328+
```
329+
330+
This will ask the user to log in and presents her with a form to authorize your
331+
client. If the user authorizes your client, she will be redirected to:
332+
333+
```
334+
http://www.example.com/oauth/callback?code=<auth code>
335+
```
336+
337+
You need the `<auth code>` from this redirect to go to step 2.
338+
339+
The preference of the user will be stored so this authorization step will
340+
redirect immediatly (without showing the form) the next time you do this for the
341+
same user.
342+
343+
344+
## 2. Get the access token
345+
To get the access token perform the following request:
346+
```plaintext
347+
HTTP/1.1 POST /users/token
348+
Content-Type: application/json
349+
Authorization: Basic <basic_auth>
350+
351+
{
352+
"grant_type": "authorization_code",
353+
"code": "<auth code>",
354+
"redirect_uri: "http://www.example.com/oauth/callback"
355+
}
356+
```
357+
358+
Where `<basic_auth>` is the basic auth digest for your client (`client_id` and
359+
`client_secret`) and `<auth_code>` is the authorization code received from step 1.
309360

310361
[jwt]: https://jwt.io
362+

_scripts/pull.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ if (process.env.GITHUB_OAUTH_TOKEN) {
7676
branch: 'v2-preview',
7777
path: 'apidocs.md',
7878
token: process.env.GITHUB_OAUTH_TOKEN,
79-
file: '_includes/draft/account/_api.md'
79+
file: '_includes/draft/account/_api.md',
80+
replace: [
81+
[/^The Things Network Account Server API/m, 'API Reference']
82+
]
8083
}, {
8184
owner: 'TheThingsIndustries',
8285
repo: 'node-ttn-oauth2',

0 commit comments

Comments
 (0)