Access to the API is allowed according to the user role and permissions defined in PowerFlex Manager. All examples in this document use the PowerFlex Manager admin account. Consult the PowerFlex User Roles and LDAP Usage Technical Notes document for details about users and roles.
The following function prompts the user to enter the credentials for the PowerFlex Manager. The access_token is extracted from the response to be used in subsequent API calls defined in other functions.
Example using curl to authenticate with a PowerFlex v3.6.x Gateway:
curl --location --request GET 'https://<PowerFlex_Gateway>/api/login' \
--header 'Accept: application/json' \
--header "Authorization: Basic $(echo -n '<Username>:<Password>' | base64)"
Example using curl to authenticate with PowerFlex Manager v4.x:
curl --location --request POST 'https://<pfxm>/rest/auth/login' --header 'Content-Type: application/json' --data-raw '{"username": "<username>", "password": "<password>"}'
import requests
import json
import getpass
import urllib3
#Authentication function saved as pfauth.py.
def authenticate(username, password):
url = 'https://pfxm.powerflex.lab/rest/auth/login'
payload = json.dumps({
'username': f'{username}',
'password': f'{password}'
})
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.post(url, headers=headers, data=payload, verify=False)
#Convert to json object and parse for access token
json_object = json.loads(response.text)
accessToken = str(json_object['access_token'])
return accessToken
#Authentication
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Headers.Add("Content-Type", "application/json")
$Headers.Add("Accept", "application/json")
$CredJson = "{`"username`": `"admin`", `"password`": `"Password`"}"
$Response = Invoke-RestMethod "https://$PFMPhost/rest/auth/login" -Method POST -Headers $Headers -Body $CredJson
$accessToken = $Response.access_token
#Create authentication header for use in API calls
$AuthHeader = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$AuthHeader.Add("Content-Type", "application/json")
$AuthHeader.Add("Accept", "application/json")
$AuthHeader.Add("Authorization", "Bearer $accessToken")
Note: The token has two expiry timers. The first expires after 10 minutes of inactivity. The second is 8 hours after successfully authenticating with the PowerFlex gateway.