Skip to content

Commit

Permalink
oauth rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
bitrequest committed Jan 19, 2024
1 parent e0a4ded commit 956b6ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 34 deletions.
8 changes: 5 additions & 3 deletions assets_js_lib_google_drive_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ function fetch_creds(k) {
"api_url": true,
"proxy": true,
"code": decodeURIComponent(k),
"redirect_uri": redirect_uri
"redirect_uri": redirect_uri,
"grant_type": "authorization_code"
}).done(function(e) {
if (e) {
let data = br_result(e);
Expand Down Expand Up @@ -128,10 +129,11 @@ function fetch_creds(k) {
function fetch_access(rt, callback) {
if (rt) {
api_proxy({
"custom": "fetch_access",
"custom": "fetch_creds",
"api_url": true,
"proxy": true,
"refresh_token": rt
"refresh_token": rt,
"grant_type": "refresh_token"
}).done(function(e) {
if (e) {
let data = br_result(e);
Expand Down
43 changes: 12 additions & 31 deletions proxy/v1/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

// Construct headers
if (isset($proxyheaders) || $method == "POST" || $bearer) {
$postheaders = array(
$postheaders = array(
"Content-Type: application/json"
);
if (isset($payload)) {
Expand All @@ -50,12 +50,12 @@
// Add Authorization header if needed
if ($bearer) {
if ($auth_token) {
if ($bearer == "amberdata") {
$postheaders[] = "x-api-key: " . $auth_token;
}
else {
$postheaders[] = "Authorization: Bearer " . $auth_token;
}
if ($bearer == "amberdata") {
$postheaders[] = "x-api-key: " . $auth_token;
}
else {
$postheaders[] = "Authorization: Bearer " . $auth_token;
}
}
if ($bearer == "tls_wildcard") {
$postheaders["tls_wildcard"] = true;
Expand Down Expand Up @@ -84,7 +84,7 @@
return;
}
if ($custom == "add") {
$result = api(null, json_encode($postdata), null, 0, "1d", null, null);
$result = api(null, json_encode($postdata), null, 0, "1d", null, null);
echo json_encode([
"ping" => $result
]);
Expand Down Expand Up @@ -114,29 +114,10 @@
return;
}
if ($custom == "fetch_creds") {
$dat = [
"MIME-type" => "application/x-www-form-urlencoded; charset=UTF-8",
"client_id" => $keys["googleauth"],
"client_secret" => $keys["google_secret"],
"code" => $postdata["code"],
"redirect_uri" => $postdata["redirect_uri"],
"grant_type" => "authorization_code"
];
$result = api("https://oauth2.googleapis.com/token", $dat, null, 0, "1d", null, null);
echo json_encode([
"ping" => $result
]);
return;
}
if ($custom == "fetch_access") {
$dat = [
"MIME-type" => "application/x-www-form-urlencoded; charset=UTF-8",
"client_id" => $keys["googleauth"],
"client_secret" => $keys["google_secret"],
"refresh_token" => $postdata["refresh_token"],
"grant_type" => "refresh_token"
];
$result = api("https://oauth2.googleapis.com/token", $dat, null, 0, "1d", null, null);
$postdata["MIME-type"] = "application/x-www-form-urlencoded; charset=UTF-8";
$postdata["client_id"] = $keys["googleauth"];
$postdata["client_secret"] = $keys["google_secret"];
$result = api("https://oauth2.googleapis.com/token", $postdata, null, 0, "1d", null, null);
echo json_encode([
"ping" => $result
]);
Expand Down

0 comments on commit 956b6ca

Please sign in to comment.