Oyster Harvest Area Closure Analysis 0.1
Prediction and analysis of NSW oyster harvest area closures.
Loading...
Searching...
No Matches
authenticate.h File Reference
#include <curl/curl.h>
#include <cjson/cJSON.h>
#include <time.h>
#include <log.h>
#include "http.h"
#include "utils.h"
Include dependency graph for authenticate.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  IBM_AuthHandle_TypeDef
 IBM token handler. More...
 

Macros

#define IBM_DEFAULT_TOKEN_NAME   "IBM_TOKEN"
 Default ENV variable name of API key. More...
 
#define IBM_ACCESS_TOKEN_SIZE   2000
 Buffer size to hold access token. More...
 
#define IBM_REFRESH_TOKEN_SIZE   50
 Buffer size of hold refresh token. More...
 

Functions

int8_t IBM_HandleAuth (IBM_AuthHandle_TypeDef *auth_handle)
 Authentication handler for IBM EIS. More...
 
CURLcode IBM_Authenticate (const char *token, IBM_AuthHandle_TypeDef *auth_handle)
 Authenticate with IBM's Environmental Intelligence Suite (EIS). More...
 
CURLcode IBM_Refresh (IBM_AuthHandle_TypeDef *auth_handle)
 Obtain a new access token from IBM's EMS. More...
 

Variables

static const char * IBM_TOKEN_URL = "https://auth-b2b-twc.ibm.com/connect/token"
 IBM authenticate (token) URL. More...
 

Macro Definition Documentation

◆ IBM_ACCESS_TOKEN_SIZE

#define IBM_ACCESS_TOKEN_SIZE   2000

Buffer size to hold access token.

◆ IBM_DEFAULT_TOKEN_NAME

#define IBM_DEFAULT_TOKEN_NAME   "IBM_TOKEN"

Default ENV variable name of API key.

◆ IBM_REFRESH_TOKEN_SIZE

#define IBM_REFRESH_TOKEN_SIZE   50

Buffer size of hold refresh token.

Function Documentation

◆ IBM_Authenticate()

CURLcode IBM_Authenticate ( const char *  token,
IBM_AuthHandle_TypeDef auth_handle 
)

Authenticate with IBM's Environmental Intelligence Suite (EIS).

Authenticate with IBM's Enviornmental Monitoring Suite.

IBM used OAuth2 for authentication. This function takes care of this process. The lengths of the tokens are:

  • Access token = 1861 bytes
  • Refresh token = 43 bytes
Parameters
tokenIBM API key to use.
auth_handleAuthenication handler for IBM tokens
Returns
CURLcode error message

◆ IBM_HandleAuth()

int8_t IBM_HandleAuth ( IBM_AuthHandle_TypeDef auth_handle)

Authentication handler for IBM EIS.

Handles authentication, checking and re-authentication of IBM EIS access tokens.

IBM_AuthHandle_TypeDef auth_handle = {0};
if(IBM_HandleAuth(&auth_handle) != 0){
return 1;
}
int8_t IBM_HandleAuth(IBM_AuthHandle_TypeDef *auth_handle)
Authentication handler for IBM EIS.
Definition: authenticate.c:19
IBM token handler.
Definition: authenticate.h:25
Note
Authentication handler must be initialised to zero.
Parameters
auth_handleAuthentication hander with tokens and expiry information.
Returns
Error code. 0 = OK 1 = ERROR

Check if initialised already

◆ IBM_Refresh()

CURLcode IBM_Refresh ( IBM_AuthHandle_TypeDef auth_handle)

Obtain a new access token from IBM's EMS.

Re-authenticate with IBM's Enviornmental Monitoring Suite.

IBM used OAuth2 for re-authentication. This function takes care of this process. The access_token length is at least 1861 characters.

char* access_token[IBM_ACCESS_TOKEN_SIZE]; // Access token to populate
IBM_Refresh(refresh_token, access_token);
CURLcode IBM_Refresh(IBM_AuthHandle_TypeDef *auth_handle)
Obtain a new access token from IBM's EMS.
Definition: authenticate.c:139
#define IBM_ACCESS_TOKEN_SIZE
Buffer size to hold access token.
Definition: authenticate.h:16
Note
Ensure malloc size if large enough to hold the returned access token (at least 1861 bytes).
Parameters
auth_handleIBM EIS authentication handler.
Returns
CURLcode error message

Variable Documentation

◆ IBM_TOKEN_URL

const char* IBM_TOKEN_URL = "https://auth-b2b-twc.ibm.com/connect/token"
static

IBM authenticate (token) URL.