Wettmannstaetten impot update & ofaa oaid scripts

This commit is contained in:
Frank Schubert
2023-07-11 11:43:15 +02:00
parent 2deeead7c6
commit 7c513a7595
10 changed files with 2781 additions and 11 deletions

View File

@@ -0,0 +1 @@
eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI5TmkwTWZMaTB4LUlzOEEzc3V1ZlgxNVJiZlROTTRrUDJ2d1lackxvNWRVIn0.eyJleHAiOjE2ODU5Nzk5NTMsImlhdCI6MTY4NTk3OTY1MywianRpIjoiYTFlZTA2ZjUtZTk0Yy00YjE1LTk5ZGQtZjNkNDg5M2M1NDRkIiwiaXNzIjoiaHR0cHM6Ly9zc28ueWlvLmF0L2F1dGgvcmVhbG1zL29haWQiLCJhdWQiOlsiaHR0cHM6Ly9hcGkub2FpZC5hdCIsImFjY291bnQiXSwic3ViIjoiNWI1ZmMyYzktMTcyNi00ZTIxLTkyNGUtYjI5MjdiMGY2MDM3IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoib2FpZC5vZmFhLmVzdGVpZXJtYXJrIiwiYWNyIjoiMSIsImFsbG93ZWQtb3JpZ2lucyI6WyJodHRwczovL2FwaS1kZW1vLm9haWQuYXQiLCJodHRwczovL2FwaS5vYWlkLmF0Il0sInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJkZWZhdWx0LXJvbGVzLW9haWQiLCJvZmZsaW5lX2FjY2VzcyIsInVtYV9hdXRob3JpemF0aW9uIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnsiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19fSwic2NvcGUiOiJlbWFpbCBvYWlkOm1nbTpyZWFkIG9haWQ6Y29kZXM6d3JpdGUgb2FpZDpjb2RlczpyZWFkIHByb2ZpbGUiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImNsaWVudEhvc3QiOiIxNzYuNjYuMTYwLjE1NCIsImNsaWVudElkIjoib2FpZC5vZmFhLmVzdGVpZXJtYXJrIiwicHJlZmVycmVkX3VzZXJuYW1lIjoic2VydmljZS1hY2NvdW50LW9haWQub2ZhYS5lc3RlaWVybWFyayIsImNsaWVudEFkZHJlc3MiOiIxNzYuNjYuMTYwLjE1NCJ9.WvBdzNge8zrNIYemmBhVTk7FtKl-8lMhTGGlVkH5yKGxcEktjZPwsu_Jg_VbxgCtNJxnFqtMaGHz6pXp4Cl1HAXAUDfjXOujalKe9o0FthdI7UVIOn500l7pS0ZnJiidgB48GqBKwkr_qUbdd6aChqhUEBjeSmGQWNTikzZhgI1xv6P8IwURPBC9yQVHN9kCrZuF_xeMFXSbuf_Yej9AWRZeHCz13kIvyTEKnRBu6rt-VfrUSBgbdAZDErOVzqeCVufn_kxViUsxYQeVX8_8vNQydiOrgXED5aTLEG0csThKx4HMPh9KMZWiJ5R797OZMfqve7j5RYjDO0Ez44tv-w

View File

@@ -0,0 +1,28 @@
<?php
$oauth_url = "https://sso.yio.at/auth/realms/oaid/protocol/openid-connect/token";
$baseurl = "https://api.oaid.at/v1";
$client_id = "oaid.ofaa.esteiermark";
$client_secret = "4a5b09ed-956c-4721-bb53-3a144fc5f55a";
$tenant = "ofaa.esteiermark";
/*
$baseurl = "https://api-demo.oaid.at/v1";
$client_id = "oaid.demo.pip";
$client_secret = "6e74e7e8-0cc2-43df-83c2-12937452b916";
*/
$ep_mgm_credits = $baseurl."/pip/mgm/credits/";
$ep_list_oaids = $baseurl."/pip/codes/";
$ep_request_oaid = $baseurl."/pip/codes/";
$ep_confirm_oaid = $baseurl."/pip/codes/{oaid}/token/";
$default_scope = ["oaid:mgm:read","oaid:codes:read","oaid:codes:write"];
$access_token = "";
$token_file = __DIR__."/.access_token";
if(file_exists($token_file)) {
$access_token = file_get_contents($token_file);
}

View File

@@ -0,0 +1,142 @@
<?php
function fetchAccessToken($oauth_url, $client_id, $client_secret, $scopes = ["oaid:codes:read"]) {
//echo "called fetchAccessToken $oauth_url\n";
global $token_file;
global $access_token;
$headers = [
"Accept: application/json",
"Content-Type: application/x-www-form-urlencoded",
];
$post_content = [
"grant_type" => "client_credentials",
"client_id" => $client_id,
"client_secret" => $client_secret,
"scope" => implode(" ", $scopes),
];
$output = postRestUrl($oauth_url, $headers, $post_content);
$output_values = json_decode($output);
if(!is_object($output_values) || !property_exists($output_values, "access_token")) {
return false;
}
$access_token = $output_values->access_token;
file_put_contents($token_file, $access_token);
return $access_token;
}
function getRestUrl($url, $headers, $params = [], $debug = false) {
//echo "called getRestUrl $url\n";
$ctx_options = ["http" => [
"ignore_errors" => true,
"method" => "GET",
"header" => $headers,
]];
$_url = $url;
if(count($params)) {
$_url .= "?".http_build_query($params);
}
if($debug) {
var_dump($_url, $ctx_options);
exit;
}
$ctx = stream_context_create($ctx_options);
$output = file_get_contents($_url, false, $ctx);
foreach($http_response_header as $h_line) {
$m = [];
if(preg_match('/HTTP\/\d+(?:\.\d+) ([245]\d+)/', $h_line, $m)) {
$response_code = $m[1];
if(substr($response_code, 0, 1) == "2") {
return $output;
} elseif($response_code == "401") {
return "__err__401";
} else {
die("getRestUrl(): $h_line");
}
}
}
}
function putRestUrl($url, $headers, $content, $content_type = "application/x-www-form-urlencoded", $follow_location = true, $debug = false) {
return postRestUrl($url, $headers, $content, $content_type, $follow_location, $debug, 'PUT');
}
function postRestUrl($url, $headers, $content, $content_type = "application/x-www-form-urlencoded", $follow_location = true, $debug = false, $method = "POST") {
//echo "called postResturl $url\n";
$ctx_options = ["http" => [
"ignore_errors" => true,
"method" => "POST",
"header" => $headers,
]];
if(!$follow_location) {
$ctx_options["http"]["follow_location"] = false;
}
if($method == "PUT") {
$ctx_options["http"]["method"] = "PUT";
}
if($content_type == "application/x-www-form-urlencoded") {
$ctx_options["http"]["content"] = http_build_query($content);
}
if($content_type == "application/json") {
$ctx_options["http"]["content"] = json_encode($content);
}
if($debug) {
var_dump($url, $ctx_options);
exit;
}
$ctx = stream_context_create($ctx_options);
$output = file_get_contents($url, false, $ctx);
//var_dump($http_response_header);
if(!$follow_location) {
return $output;
}
foreach($http_response_header as $h_line) {
$m = [];
$status_code_types = "245";
if(!$follow_location) {
$status_code_types = "2345";
}
if(preg_match('/HTTP\/\d+(?:\.\d+) ([245]\d+)/', $h_line, $m)) {
$response_code = $m[1];
if(substr($response_code, 0, 1) == "2") {
return $output;
} elseif(substr($response_code, 0, 1) == "3") {
return $output;
} elseif($response_code == "401") {
return "__err__401";
} else {
die("postRestUrl(): $h_line\n");
}
}
}
}
function guidv4($data = null) {
// Generate 16 bytes (128 bits) of random data or use the data passed into the function.
$data = $data ?? random_bytes(16);
assert(strlen($data) == 16);
// Set version to 0100
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
// Set bits 6-7 to 10
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
// Output the 36 character UUID.
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}