Authenticate to Rampiva Automate without an API Key

The material in this document is for informational purposes only. The products it describes are subject to change without prior notice, due to the manufacturer’s continuous development program. Rampiva makes no representations or warranties with respect to this document or with respect to the products described herein. Rampiva shall not be liable for any damages, losses, costs or expenses, direct, indirect or incidental, consequential or special, arising out of, or related to the use of this material or the products described herein.

Introduction

The recommended way of authenticating to Rampiva Automate when using the API is using an API Key. This feature requires a Premium-edition license. To learn more about using an API Key, see https://rampiva.atlassian.net/wiki/spaces/KB/pages/1130921985

If an API Key is not available, it’s possible to use emulate the messages exchanged by a browser sent when logging in a user with a username and password. This method is not available when the underlying authentication service is OIDC (such as a Azure AD account) and has the downside of requiring the API client to handle the refresh token mechanism.

This article provides an example of logging in without an API Key and the illustrates the message errors returned when the authentication token is not refreshed.

Prerequisites 

  • Rampiva Automate 6.0 or later


Instructions

A. Authenticate with a username and password

1

Use the sample Python script in the right column to authenticate to Automate using a username and password, and immediately query the user settings.

The Internal scope can be used for testing and must first be enabled in the Scheduler configuration YAML file. See https://downloads.rampiva.com/automate/release/guides/scheduler/en_US/installation-guide.html#_scheduler_service_settings for details.

Replace the serviceLocation with the location at which the API is available in your environment.

import requests serviceLocation = 'http://localhost/api/v1' login={ 'username': 'jsmith', 'password': 'Password1!', 'scope': 'Internal' } response = requests.post(serviceLocation+'/users/password', json=login) if (response.status_code != 200): raise Exception('Authentication error',response.json()) authToken = response.json()['token'] print('Got authentication token of length',len(authToken)) authHeaders = { 'Authorization': 'Bearer '+ authToken } userSettings = requests.get(serviceLocation+'/scheduler/userSettings', headers=authHeaders).json() print (userSettings)
2

To simulate the effect of using an expired authentication token, add a delay between the authentication and the querying of the API. Use the sample Python script in the right column to perform this.

import requests import time serviceLocation = 'http://localhost/api/v1' login={ 'username': 'jsmith', 'password': 'Password1!', 'scope': 'Internal' } response = requests.post(serviceLocation+'/users/password', json=login) if (response.status_code != 200): raise Exception('Authentication error',response.json()) authToken = response.json()['token'] print('Got authentication token of length',len(authToken)) authHeaders = { 'Authorization': 'Bearer '+ authToken } time.sleep(61) userSettings = requests.get(serviceLocation+'/scheduler/userSettings', headers=authHeaders).json() print (userSettings)
3

The authentication token expiration can be disabled by adding disableAuthTokenExpiration: true in the Scheduler configuration YAML file. See https://downloads.rampiva.com/automate/release/guides/scheduler/en_US/installation-guide.html#_scheduler_service_settings for details.