Authentication

Authentication to LRS Connect API uses OAuth 2.0.

  • Your api key and secret are accessed from the user management page within LRS Connect.
  • Credentials can be deleted and regenerated to control access.
  • A single set of credentials can provide access to data for multiple accounts.
  • Data for inactive accounts will not be returned.

/rest/v3/oauth/token

Method needs to invoked with a header value

HeaderValueDescription
userExample:

M0lZZZhFUDRIOFY1R0lSNUw0MEsx...vbE5UMEZ0NWVVOEFkYkkw
user header value should contain a base64 encoded string consisting of the API Key ID and API Key Secret which can be found within the user management page of LRSConnect.

e.g. base64(API_ID:API_SECRET

Request

In order to receive token, ?grant_type=client_credentials MUST be appended to token URI.

// OAuth (POST https://connect.lrsus.com/rest/v3/oauth/token)

$.ajax({
    url: "https://connect.lrsus.com/rest/v3/oauth/token?grant_type=client_credentials",
    type: "POST",
    headers: {
        "user": "M0lYUUhFUDRIOFY1...bE5UMEZ0NWVVOEFkYkkw",
    },
})
.done(function(data, textStatus, jqXHR) {
    console.log("HTTP Request Succeeded: " + jqXHR.status);
    console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
    console.log("HTTP Request Failed");
})
.always(function() {
    /* ... */
});
import java.io.IOException;
import org.apache.http.client.fluent.*;

public class SendRequest
{
  public static void main(String[] args) {
    sendRequest();
  }
  
  private static void sendRequest() {
    
    // OAuth (POST )
    
    try {
      
      // Create request
      Content content = Request.Post("https://connect.lrsus.com/rest/v3/oauth/token?grant_type=client_credentials")
      
      // Add headers
      .addHeader("user", "M0lYUUhFUDRIOFY1...bE5UMEZ0NWVVOEFkYkkw")
      
      // Fetch request and return content
      .execute().returnContent();
      
      // Print content
      System.out.println(content);
    }
    catch (IOException e) { System.out.println(e); }
  }
}
// OAuth (GET https://connect.lrsus.com/rest/v3/oauth/token)

NSURL* URL = [NSURL URLWithString:@"https://connect.lrsus.com/rest/v3/oauth/token?grant_type=client_credentials"];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = @"POST";

// Headers

[request addValue:@"M0lYUUhFUDRIOFY1...bE5UMEZ0NWVVOEFkYkkw" forHTTPHeaderField:@"user"];

// Connection

NSURLConnection* connection = [NSURLConnection connectionWithRequest:request delegate:nil];
[connection start];
curl -X "POST" "https://connect.lrsus.com/rest/v3/oauth/token?grant_type=client_credentials" \
	-H "user: M0lYUUhFUDRIOFY1...bE5UMEZ0NWVVOEFkYkkw"
# Install the Python Requests library:
# `pip install requests`

import requests

def send_request():
    # OAuth (GET https://connect.lrsus.com/rest/v3/oauth/token)

    try:
        r = requests.post(
            url="https://connect.lrsus.com/rest/v3/oauth/token?grant_type=client_credentials",
            headers = {
                "user":"M0lYUUhFUDRIOFY1...bE5UMEZ0NWVVOEFkYkkw",
            },
        )
        print('Response HTTP Status Code   : {status_code}'.format(status_code=r.status_code))
        print('Response HTTP Response Body : {content}'.format(content=r.content))
    except requests.exceptions.RequestException as e:
        print('HTTP Request failed')

Response 200 (application/json)

The response will contain a "Bearer" token that must be passed on subsequent requests. The token is valid for 1200 seconds by default.

{
  "expires_in": "1200",
  "token_type": "Bearer",
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0ODQxNTU3MzksInN1YiI6IjVTMEZCMUZJQzFSSE5HOUNFSElTNVBHUDAiLCJpc3MiOiJodHRwczovL2FwaS5zdG9ybXBhdGguY29tL3YxL2FwcGxpY2F0aW9ucy81c3VtdGdod3A2Vkw2cUdTbUN3VDJjIiwiaWF0IjoxNDg0MTU0NTM5fQ.SInKB-Q7Ouhz43itJsmxBvr5vgyhUmkwf8Zga8AF7Oc"
}

The token is passed as an Authorization header value.

HeaderValueDescription
AuthorizationExample:

Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0MzU3N...FWFxGl3odgJ25T0O7kwq-hca2QDtSIWKUFHTpBNU97c
Concatenate value of "Bearer" and access_token returned from /rest/v3/oauth/token method.

SSL

SSL is used to encrypt all requests to & from LRS Connect API.