Skip to main content

Authentication

All NetFoundry APIs require an authentication token. Authentication is delegated to an identity provider—Cognito, Auth0, or Okta. Use your API account credentials to obtain an access token.

Cognito

Follow this example if your authentication URL is for Amazon Cognito:

NETFOUNDRY_API_TOKEN=$( \
curl --user ${NETFOUNDRY_CLIENT_ID}:${NETFOUNDRY_PASSWORD} \
--request POST ${NETFOUNDRY_OAUTH_URL} \
--header 'content-type: application/x-www-form-urlencoded' \
--data 'grant_type=client_credentials&scope=https%3A%2F%2Fgateway.production.netfoundry.io%2F%2Fignore-scope' | \
jq -r .access_token \
)

This creates an environment variable NETFOUNDRY_API_TOKEN to hold the token after a successful request. The contents of this variable are used in all subsequent requests.

  • Substitute your API account client ID and password for ${NETFOUNDRY_CLIENT_ID} and ${NETFOUNDRY_PASSWORD}.
  • Substitute the authentication URL for your API account in ${NETFOUNDRY_OAUTH_URL}.
  • The example uses jq to extract the access token from the response.

Auth0

Follow this example if your authentication URL is for Auth0:

NETFOUNDRY_API_TOKEN=$( \
curl \
--request POST \
--silent \
--show-error \
--header 'content-type: application/json' \
--data '{
"client_id":"---redacted----",
"client_secret": "---redacted----",
"audience":"https://gateway.production.netfoundry.io/",
"grant_type":"client_credentials"
}' \
https://netfoundry-production.auth0.com/oauth/token | \
jq -r .access_token \
) && echo $NETFOUNDRY_API_TOKEN
  • The command creates an environment variable NETFOUNDRY_API_TOKEN to hold the token after a successful request. The contents of this variable are used in all subsequent requests.
  • The example uses cURL to perform the request.
  • Insert your actual client ID in place of ---redacted----.
  • Insert your actual client secret in place of ---redacted----.
  • The example uses jq to parse the Auth0 response and extract the token.
  • The echo at the end prints the extracted token for convenience and debugging.

API request using access token

Make an HTTP request by passing the access token in the Authorization header. This example fetches your networks:

curl https://gateway.production.netfoundry.io/core/v2/networks \
--header "Authorization: Bearer ${NETFOUNDRY_API_TOKEN}"
  • The URL fetches networks (see also Listing networks).
  • The Authorization header transmits the Bearer token stored in NETFOUNDRY_API_TOKEN.