Sariska utilizes JSON Web Tokens (JWTs) to securely authenticate users and devices. JWTs are a standardized, structured, and self-contained method for conveying information between clients as JSON objects. They serve as a mechanism for asserting claims exchanged between two parties. In the context of a JWT, a claim is a declaration about a company or user, accompanied by additional metadata about the token itself. The payload, which is maintained in JSON format, contains a set of claims. JWTs are digitally signed and encrypted for enhanced security.
Sariska generates these tokens on its servers. A single token can be used to access all Sariska services.
asyncfunctionfetchToken () {constpayload= { method:"POST", headers: {'Content-Type':'application/json" }, body:JSON.stringify({ apiKey:"{your-api-key}", user: { // optional id:"ytyVgh", name:"Nick", email:"nick@gmail.com", avatar:"https://some-storage-location/nick.jpg", moderator:true// If participant is moderator set to true, otherwise leave blank.// Sariska will automatically appoint the first participant as moderator if the moderator leaves. } }) };try {constresponse=awaitfetch("https://api.sariska.io/api/v1/misc/generate-token", payload);if (response.ok) {constjson=awaitresponse.json();consttoken=json.token;return token; } } catch (error) {console.log(error); }}awaitfetchToken();
import'dart:convert'as convert;import'package:http/http.dart'as httpString fetchToken() async { final body = { user: {// optional id: "ytyVgh", name: "Nick", email: "nick@gmail.com", avatar: "https://some-storage-location/nick.jpg", moderator: true// If participant is moderator set to true, otherwise leave blank.// Sariska will automatically appoint the first participant as moderator if the moderator leaves. }, apiKey: "{your-api-key}" };var url ='https://api.sariska.io/api/v1/misc/generate-token';final response =await http.post(url, headers: {"Content-Type":"application/json"}, body: body);if (response.statusCode ==200) {// If the server did return a 200 OK response,// then parse the JSON.var body =jsonDecode(response.body);return body['token']; } else {// If the server did not return a 200 OK response,// then throw an exception.throwException('Failed to load data'); }}awaitfetchToken();
let json: [String:Any] = ["apiKey":"{your-api-key}"]let body =try? JSONSerialization.data(withJSONObject: json)guardlet url =URL(string:"https://api.sariska.io/api/v1/misc/generate-token")else {fatalError("URL could not be reached")}var request =URLRequest(url: url)request.httpMethod ="POST"request.httpBody = bodyrequest.addValue("application/json", forHTTPHeaderField:"Content-Type")request.addValue("application/json", forHTTPHeaderField:"Accept")let session = URLSession.sharedlet task = session.dataTask(with: request){ (data, response, error) iniflet data = data {iflet token =String(data: data, encoding:String.Encoding.utf8){print(token) } }else{print(error ??"Error with data in URLSession task") }}task.resume()
A unique identifier for the user. If not provided, Sariska will generate one automatically.
exp
Optional
The expiration time of the token. The default is 24 hours. You can specify a custom expiration time using the following formats: 2 seconds, 2 minutes, 2 hours, 2 days, 2 weeks, or 2 years.
nbf
Optional
The time before which the token is not valid. The token will not be accepted for processing until the current date/time is after or equal to the value of this field. You can specify a custom nbf value using the following formats: 2 seconds, 2 minutes, 2 hours, 2 days, 2 weeks, or 2 years.
scope
Optional
The scope of the token. By default, tokens can be used for integrating media, messaging, and collaboration services. You can restrict the scope to one or more of these services using the following values: messaging, co-browsing, or media. Leave this field blank to use all services.