Cet article vous a-t-il été utile ?
Comment pourrions-nous l'améliorer ?
Lyve Cloud uses a token to authenticate access to the Lyve Cloud Account API. The Token is obtained by calling an endpoint that uses the Account ID, Access Key, and Secret Key. It returns a valid time-bound token, where the default expiration duration is 24 hours. When a token expires, the account API returns HTTP 400
code, after which the client application needs to obtain a new token.
Each request to an API endpoint must include the bearer header value. This value requires specifying a token in the authorization header of a request.
A token is a unique string. Tokens eliminate the need for passing user credentials with requests. Such a token is issued by the /auth/token endpoint.
A POST to /auth/token is used to exchange user credentials for an access token.
POST /auth/token
{ "accountId": "string", "accessKey": "string", "secret": "string" }
Name | In | Type | Required | Description |
---|---|---|---|---|
accountId | body | string | True | The Account ID is a unique identifier of the Lyve Cloud Account. The Account ID is created during the customer onboarding and is unique across all Lyve Cloud accounts. |
accessKey | body | string | True | The access key is generated when you generate Account API credentials. For more information, see Using Account API. |
secret | body | string | True | The secret key is generated when you generate Account API credentials. For more information, see Using Account API. |
package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{ "application/json", }, "Accept": []string{ "application/json", }, } jsonReq := `{"key":"value"}` // replace with your JSON request data := bytes.NewBuffer([]byte(jsonReq)) req, err := http.NewRequest("POST", "https://api.lyvecloud.seagate.com/v2/auth/token/", data) if err != nil { // handle error } req.Header = headers client := &http.Client{} resp, err := client.Do(req) if err != nil { // handle error } // handle response _ = resp }
import java.net.HttpURLConnection; import java.net.URL; import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { try { URL obj = new URL("https://api.lyvecloud.seagate.com/v2/auth/token/"); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("POST"); int responseCode = con.getResponseCode(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.println(response.toString()); } catch (Exception e) { e.printStackTrace(); } } }
const inputBody = `{ "accountId": "string", "accessKey": "string", "secret": "string" }`; const headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' }; fetch('https://api.lyvecloud.seagate.com/v2/auth/token/', { method: 'POST', body: inputBody, headers: headers }) .then(function(res) { return res.json(); }).then(function(body) { console.log(body); });
import requests headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } data = { "accountId": "string", "accessKey": "string", "secret": "string" } r = requests.post('https://api.lyvecloud.seagate.com/v2/auth/token/', headers=headers, json=data) print(r.json())
require 'rest-client' require 'json' headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json' } data = { "accountId" => "string", "accessKey" => "string", "secret" => "string" } result = RestClient.post 'https://api.lyvecloud.seagate.com/v2/auth/token/', data.to_json, headers p JSON.parse(result)
Status Code | Description | Return JSON payload | ||||||
---|---|---|---|---|---|---|---|---|
200 | OK The session token is returned successfully to use in subsequent API calls.The expiration time of the token is returned in response, ater the expiration duration the token is expired. |
{ "token": "string", "expirationSec": 864000, }
|
||||||
400 | Bad request The request is invalid and has invalid information. |
{ "code": "string", "message": "string" }
|
||||||
403 | Authentication failed. | { "code": "string", "message": "string" }
|
||||||
500 | Internal Server Error. | { "code": "string", "message": "string" }
|
||||||
503 | Service Unavailable | { "code": "string", "message": "string" }
|
To access the API, you must request an access token when authenticating a user. The GET /auth/token is used to validate a session and return the remaining duration for that session.
The GET API allows validating a session. It returns the remaining duration of the token.
GET /auth/token
package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{ "application/json", }, "Authorization": []string{ "Bearer {access-token}", }, } data := bytes.NewBuffer([]byte{ jsonReq, }) req, err := http.NewRequest("GET", "https://api.lyvecloud.seagate.com/v2/auth/token/", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... }
import java.net.HttpURLConnection; import java.net.URL; import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { try { URL obj = new URL("https://api.lyvecloud.seagate.com/v2/auth/token/"); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.println(response.toString()); } catch (Exception e) { e.printStackTrace(); } } }
const headers = { 'Accept': 'application/json', 'Authorization': 'Bearer {access-token}' }; fetch('https://api.lyvecloud.seagate.com/v2/auth/token/', { method: 'GET', headers: headers }) .then(function(res) { return res.json(); }).then(function(body) { console.log(body); });
import requests headers = { 'Accept': 'application/json', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://api.lyvecloud.seagate.com/v2/auth/token/', headers=headers) print(r.json())
require 'rest-client' require 'json' headers = { 'Accept' => 'application/json', 'Authorization' => 'Bearer {access-token}' } result = RestClient.get 'https://api.lyvecloud.seagate.com/v2/auth/token/', headers: headers p JSON.parse(result)
Status Code | Description | Return JSON payload | ||||||
---|---|---|---|---|---|---|---|---|
200 | OK A session token is valid and is in effect. |
{ "expirationSec": 0 }
|
||||||
400 | Bad request Either the token is expired or not valid. |
{ "code": "string", "message": "string" }
|
||||||
500 | The server encountered an internal error. | { "code": "string", "message": "string" }
|
||||||
503 | Service Unavailable | { "code": "string", "message": "string" }
|