User Authorization

The intent of this document is to share how to do the following:

  • Create a User on this API to make API calls
  • Verify User on Analytics API
  • Make API Calls

How to Create a User

This step will teach you how to create a user on Analytics API. You will not be able to login as that user until that user is verified in the next step.

Option 1:

Option 2:

  • Replace email, password, & name to your own credentials in the following code snippet
  • Run the python code snippet

import requests
email = 'user@example.com'
password = 'super_secure_password'
name = 'John Doe'
json_request = {'email': email, 'password': password, 'name': name}
response = requests.post('http://analyticsapi.erndc.com/auth/register', json=json_request)
response.raise_for_status()
print(response.json())

Option 3:

  • Replace email, password, & name to your own credentials in the following code snippet
  • Run the CURL code snippet

curl -X 'POST' \
'http://analyticsapi.erndc.com/auth/register' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"email": "user@example.com",
"password": "super_secure_password",
"name": "John Doe"
}'

How to Verify your User

This step will teach how to verify the user on AnalyticsAPI

  • If you are an internal LibDib developer, refer to the following Documentation
  • If you are not an internal LibDib developer, please contact your system administrator to help you with this task
  • All Endpoints are protected so in order to access a particular tag of endpoint, you will need to be given elevated privileges to do so. Please contact your system administrator for this task.

How to get started with the API

This step will show you different ways to make API calls. Redoc and Swagger UI Documentation can be referenced using the side navigation bar.

Option 1:

  • Navigate to Swagger UI
  • Click `Authorize` at the top right and login by inputting your verified user's username (email) and password and click Authorize in order to log in.
  • Scroll down to endpoint, click `Try it out`, fill out correct values, and click `Execute` to see the results

Option 2:

  • Request an Access Token:

curl -X 'POST' \
'http://analyticsapi.erndc.com/auth/jwt/login' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d 'username=user@example.com&password=super_secure_password'

  • Input Access Token into header of request:

curl -X 'GET' \
'http://127.0.0.1:8000/api/v1/endpoint' \
-H 'accept: application/json' \
-H 'Authorization: Bearer __access_token__'

Option 3:

  • Replace Email & Password in python code snippet below
  • Run the python code snippet for the appropriate endpoint

import requests
data = {'username': 'user@example.com', 'password': 'super_secure_password'}
access_token = requests.post(f'http://analyticsapi.erndc.com/auth/jwt/login', data=data).json()['access_token']
headers = {'Authorization': 'Bearer {}'.format(access_token)}
response = requests.post('http://analyticsapi.erndc.com/api/v1/endpoint', headers=headers)