Step3: Obtaining an access token to download the model
Step3: Obtaining an access token to download the model
Since all information is stored on tangl servers and requires authorization and appropriate permissions, you need to get a JWT access token.
The token can be obtained in different ways. For example, via the external authorization window of the tangl authorization server, or via a request with input of details.
This is the method we will use.
The access token is given by the following details:
- Email of the user's account
- Password of the user account
- Client API Id
- Client API secret
For demonstration purposes, we will use the Demo account for third-party developers and its details.
Also for convenience we will place all additional functions of requests to tangl server in a separate file** functions.js**
For calls we'll use axios. You can also use any other way to send requests.
Add axios to the imports in** functions.js**:
import axios from "axios";
Create a function to get the token by props in functions.js:
const TANGL_AUTH_SERVER = "https://auth.tangl.cloud"
export let tanglToken = undefined;
export async function fetchToken() {
//post request
const response = await axios.post(TANGL_AUTH_SERVER + "/connect/token", {
client_id: "e35e3f8b-8197-5b4d-8249-3a077cfedc50", //Demo API client
client_secret: "ff7eb513-db87-b66d-f743-3a077cfedc51", //Demo API client
grant_type: "password",
username: "devdemo@tangl.cloud", //Demo account
password: "Devdemo1!", //Demo account
},
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
})
if (response?.data?.access_token) {
//store token
tanglToken = response.data.access_token;
console.info("Acces token is fetched: ", response.data.access_token)
}
}
Use the get token function in index.js:
import {fetchToken, tanglToken} from "./functions.js";
...
//fetching access token
await fetchToken()
The browser console should display a message with the token:
Acces token is fetched: <ACCES_TOKEN>
After receiving the token, set it in the scene manager:
sceneManager.setToken(tanglToken)