From f4cd3d62e9ded26eb18bc170f3e1c6519ccea64f Mon Sep 17 00:00:00 2001 From: Jason Hu Date: Wed, 12 Sep 2018 01:20:34 -0700 Subject: [PATCH] Add some access token programming examples (#84) * Add some access token samples * Update auth_api.md --- docs/auth_api.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/auth_api.md b/docs/auth_api.md index 4f3651f9..4b31ac7d 100644 --- a/docs/auth_api.md +++ b/docs/auth_api.md @@ -178,6 +178,42 @@ For HTTP requests, pass the token type and access token as the authorization hea Authorization: Bearer ABCDEFGH ``` +### Example: cURL + +```shell +curl -X GET \ + https://your.awesome.home/api/error/all \ + -H 'Authorization: Bearer ABCDEFGH' +``` + +### Example: Python + +```python +import requests + +url = "https://your.awesome.home/api/error/all" +headers = { + 'Authorization': "Bearer ABCDEFGH", +} +response = requests.request('GET', url, headers=headers) + +print(response.text) +``` + +### Example: NodeJS +```JavaScript +fetch('https://your.awesome.home/api/error/all', { + headers: { Authorization: 'Bearer ABCDEFGH' } +}).then(function (response) { + if (!response.ok) { + return Promise.reject(response); + } + return response.text(); +}).then(function (body ) { + console.log(body); +}); +``` + If the access token is no longer valid, you will get a response with HTTP status code 401 unauthorized. This means that you will need to refresh the token. If the refresh token doesn't work, the tokens are no longer valid and so the user is no longer logged in. You should clear the user's data and ask the user to authorize again. [oauth2-spec]: https://tools.ietf.org/html/rfc6749