Small fix for the oauth code which might enable dropbox to work too.

This commit is contained in:
Robin Krom 2020-10-26 23:24:21 +01:00
commit 0b09885a1a
2 changed files with 26 additions and 8 deletions

View file

@ -1,7 +1,20 @@
<script language="JavaScript"> <script language="JavaScript">
var urlPart = window.location.href.split('?')[1]; // Build the search query by using the hash (anchor) too
var anchor = urlPart.split("#")[1]; var search = window.location.search;
var searchQuery = urlPart.split("#")[0]; var searchQuery = "";
if (search.length > 1) {
search = search.split('?')[1];
searchQuery = search;
}
var anchor = window.location.hash;
if (anchor.length > 1) {
anchor = anchor.split('#')[1];
}
if (searchQuery.length > 0 && anchor.length > 0) {
searchQuery = search + "&" + anchor;
} else {
searchQuery = anchor;
}
function getQueryVariable(query, variable) { function getQueryVariable(query, variable) {
var vars = query.split('&'); var vars = query.split('&');
@ -14,7 +27,7 @@
return null; return null;
} }
var error = getQueryVariable(anchor, "error"); var error = getQueryVariable(searchQuery, "error");
if (error != null) { if (error != null) {
// Handle error? // Handle error?
window.console.error("Error: " + error); window.console.error("Error: " + error);
@ -25,10 +38,15 @@
// Build json object from the values provided by the oauth redirect // Build json object from the values provided by the oauth redirect
var jsonObject = {}; var jsonObject = {};
var vars = anchor.split('&'); var vars = searchQuery.split('&');
for (var i = 0; i < vars.length; i++) { for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('='); var pair = vars[i].split('=');
jsonObject[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); var propertyName = decodeURIComponent(pair[0]);
var propertyValue = decodeURIComponent(pair[1]);
if (propertyName == "state") {
continue;
}
jsonObject[propertyName] = propertyValue;
} }
// Send the data to the server, uses JQuery // Send the data to the server, uses JQuery

View file

@ -1,7 +1,7 @@
--- ---
layout: oauth layout: oauth
title: Dropbox authorization title: Dropbox authorization
permalink: /oauth/dropbox permalink: /authorize/dropbox
categories: [oauth] categories: [oauth]
tags: [uses_alerts] tags: [uses_alerts]
comments: [] comments: []