The Get_QRCode
method is used to build a QRCode in GIF/PNG/JPG/TXT format.
It requires the uri
string of the QRCode built with the method OpenOTP.TOTP_URI
or OpenOTP.HOTP_URI
It is possible to specify some optionnal parameters to design the QRCode :
size
: Integer parameter between 1 and 10 with 3 as default value.margin
: Integer parameter between 0 and 5 with 1 as default value.format
: Different image format for the QRCode (GIF, PNG, JPG and TXT) with GIF as default value.
This method returns the QRCode image in the specified format for the given 'uri' string. The image data is base64-encoded.
import requests
import json
# Define the method and parameters
method = 'Get_QRCode'
params = {
'uri': 'otpauth://totp/My%20token?secret=yfhoqgb6ch3fslmnpncsmynsdjotadyr&algorithm=SHA1&digits=6&issuer=My%20Service&period=30&userid=john&domain=rcdevsdocs&endpoint=https%3A%2F%2Fmy_webadm_srv%2Fws%2Fopenotp%2F&session=aN1JBKnmEMLt3lAV&version=1',
'size': 5,
'margin': 1,
'format': 'PNG'
}
# Create the request payload
request_payload = {
'jsonrpc': "2.0",
'method': method,
'params': params,
'id': 0
}
# Convert payload to JSON
json_payload = json.dumps(request_payload)
# Define the URL and credentials
url = "https://webadm1.rcdevsdocs.com/manag/"
auth = ("RCDEVSDOCS\\administrator", "password")
# Define the headers
headers = {
"Content-Type": "application/json",
"Connection": "close"
}
# Make the POST request
response = requests.post(url, data=json_payload, headers=headers, auth=auth, verify=False)
# Print the HTTP response code and response content
print(f"HTTP response code: {response.status_code}")
print(response.json())
<?php
#!/bin/php
$method = 'Get_QRCode';
$params = array(
'uri' => 'otpauth://totp/My%20token?secret=yfhoqgb6ch3fslmnpncsmynsdjotadyr&algorithm=SHA1&digits=6&issuer=My%20Service&period=30&userid=john&domain=rcdevsdocs&endpoint=https%3A%2F%2Fmy_webadm_srv%2Fws%2Fopenotp%2F&session=aN1JBKnmEMLt3lAV&version=1',
'size' => 5,
'margin' => 1,
'format' => 'PNG'
);
$request = array(
'jsonrpc' => "2.0",
'method' => $method,
'params' => $params,
'id' => 0
);
$json = json_encode($request);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://webadm1.rcdevsdocs.com/manag/");
curl_setopt($ch, CURLOPT_USERPWD, "RCDEVSDOCS\\administrator:password");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("connection: close"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$out = curl_exec($ch);
curl_close($ch);
print_r(json_decode($out));
?>
# Define the method and parameters
$method = 'Get_QRCode'
$params = @{
uri = 'otpauth://totp/My%20token?secret=yfhoqgb6ch3fslmnpncsmynsdjotadyr&algorithm=SHA1&digits=6&issuer=My%20Service&period=30&userid=john&domain=rcdevsdocs&endpoint=https%3A%2F%2Fmy_webadm_srv%2Fws%2Fopenotp%2F&session=aN1JBKnmEMLt3lAV&version=1'
size = 5
margin = 1
format = 'PNG'
}
# Create the request payload
$requestPayload = @{
'jsonrpc' = '2.0'
'method' = $method
'params' = $params
'id' = 0
}
# Convert the request payload to JSON
$jsonPayload = $requestPayload | ConvertTo-Json
# Define the URL and credentials
$url = "https://webadm1.rcdevsdocs.com/manag/"
$auth = "RCDEVSDOCS\administrator:password"
# Make the POST request
$response = Invoke-RestMethod -Uri $url -Method Post -Body $jsonPayload -Headers @{ "Content-Type" = "application/json" } -Credential (New-Object System.Management.Automation.PSCredential($auth, (ConvertTo-SecureString "password" -AsPlainText -Force))) -SkipCertificateCheck
# Output the response
Write-Host "HTTP Response Code: $($response.status_code)"
Write-Host $response | ConvertTo-Json