Authentication
Exchange your NSL client credentials for a short-lived OAuth token. Reuse it for every subsequent request until it expires.
How It Works
- Call
POST /oauth/tokenwith your NSL client id + secret. - Cache the token for 60 minutes; refresh proactively at ~55 minutes.
- Send
Authorization: Bearer <token>on every downstream request.
tip
Tokens last 60 minutes. Prepare to refresh before they expire to avoid 401s.
Token Request Payload
{
"client_id": "<your NSL client id>",
"client_secret": "<your NSL client secret>",
"audience": "https://api.nearspacelabs.com",
"grant_type": "client_credentials"
}
Code Examples
- Python
- JavaScript
- Bash
import requests
NSL_ID = "YOUR NSL ID"
NSL_SECRET = "YOUR NSL SECRET"
def get_auth_token():
auth_headers = {'content-type': 'application/json'}
post_body = {
'client_id': NSL_ID,
'client_secret': NSL_SECRET,
'audience': 'https://api.nearspacelabs.com',
'grant_type': 'client_credentials'
}
req = requests.post(
'https://api.nearspacelabs.net/oauth/token',
json=post_body,
headers=auth_headers
)
req.raise_for_status()
return req.json()['access_token']
auth_token = get_auth_token()
print(f"Token acquired: {auth_token[:20]}...")
const fetch = require('node-fetch');
const NSL_ID = "YOUR NSL ID";
const NSL_SECRET = "YOUR NSL SECRET";
async function getAuthToken() {
const authHeaders = { 'Content-Type': 'application/json' };
const postBody = {
client_id: NSL_ID,
client_secret: NSL_SECRET,
audience: 'https://api.nearspacelabs.com',
grant_type: 'client_credentials'
};
const response = await fetch('https://api.nearspacelabs.net/oauth/token', {
method: 'POST',
headers: authHeaders,
body: JSON.stringify(postBody)
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
return data.access_token;
}
getAuthToken().then(token => console.log(`Token: ${token.slice(0, 20)}...`));
TOKEN=$(curl -s -X POST https://api.nearspacelabs.net/oauth/token \
-H "Content-Type: application/json" \
-d '{
"client_id": "YOUR NSL ID",
"client_secret": "YOUR NSL SECRET",
"audience": "https://api.nearspacelabs.com",
"grant_type": "client_credentials"
}' | jq -r '.access_token')
echo "Token: ${TOKEN:0:20}..."