Skip to main content

Authentication

Exchange your NSL client credentials for a short-lived OAuth token. Reuse it for every subsequent request until it expires.

How It Works

  1. Call POST /oauth/token with your NSL client id + secret.
  2. Cache the token for 60 minutes; refresh proactively at ~55 minutes.
  3. 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"
}

Token Response

{
"access_token": "eyJ...",
"expires_in": 3600,
"token_type": "Bearer"
}
FieldDescription
access_tokenPass this as Authorization: Bearer <access_token> on every downstream request.
expires_inSeconds until the token expires (typically 3600). Use this to schedule refreshes.
token_typeAlways Bearer.
tip

Refresh when current_time > token_issued_at + expires_in - 300 to keep a 5‑minute safety buffer.

Code Examples

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]}...")