Commit 9bfd089a authored by Jin's avatar Jin

Merge branch 'fix-oauth' into 'master'

Fix oauth



See merge request !3
parents 549646e9 65f82ea2
......@@ -21,7 +21,7 @@
<div id="modal_dialog_message"></div>
</div>
</div>
<h2>Available Netatmo vDCs:</h2>
<h2>Available vDCs:</h2>
<div id="empty"></div>
<table id="device_list" class="generic rounded">
<thead>
......
......@@ -19,9 +19,7 @@ var vdc_config =
var vdc_render_no_devices = function()
{
$("#device_list").hide();
$("#empty").text("No Netatmo vDCs found, check if your Netatmo vDC " +
"is running.");
$("#empty").text("No Netatmo vDCs found, check your addon and package setup.");
};
......@@ -114,20 +112,15 @@ var vdc_get_client_id_callback = function(device, data)
if (client_id.length === 0)
{
vdc_show_message("Error",
"Could not get client id for authentication", true);
vdc_show_message("Error", "Could not get client id for authentication", true);
return;
}
var url = "https://api.netatmo.net/oauth2/authorize?client_id=" +
client_id + "&redirect_uri=" +
encodeURIComponent(window.location.origin + "/" +
window.location.pathname) +
"&state=" + device.dSUID;
var redirect_uri = encodeURIComponent(window.location.origin + window.location.pathname);
var url = "https://api.netatmo.net/oauth2/authorize?response_type=code&client_id=" +
client_id + "&redirect_uri=" + redirect_uri + "&state=" + device.dSUID + "&scope=read_station";
$("<form action=\"" + url + "\" method=\"POST\">" +
'<input type="hidden" name="aid">' +
'</form>').appendTo($(document.body)).submit();
top.location.href=url;
}
var vdc_show_password_prompt = function(title, message, callback)
......@@ -207,6 +200,14 @@ var vdc_auth_button_clicked = function(dsuid, evt)
callback).fail(vdc_request_failed);
};
var vdc_auth2_button_clicked = function(dsuid, evt)
{
var redirect_uri = encodeURIComponent(window.location.origin + window.location.pathname);
var url = "https://api.netatmo.net/oauth2/authorize?response_type=code&client_id=" +
"52823f931877590c917b23f7" + "&redirect_uri=" + redirect_uri + "&state=" + dsuid + "&scope=read_station";
top.location.href=url;
}
var vdc_render_add_device = function(dsuid, connected)
{
var device = g_vdcs[dsuid];
......@@ -239,6 +240,7 @@ var vdc_render_add_device = function(dsuid, connected)
{
vdc_auth_button_clicked(dsuid, evt);
};
$("#btn_" + dsuid).click(callback);
};
......@@ -294,7 +296,7 @@ var vdc_device_query_callback = function(device, data)
{
modeluid = property.value;
}
else if (property.name === "x-netatmo-connectionStatus")
else if (property.name === "x-netatmo-connection-status")
{
connected = property.value;
}
......@@ -343,10 +345,14 @@ var vdc_check_auth = function()
g_auth.dSUID = undefined;
g_auth.code = undefined;
};
$.getJSON("/json/property/vdcquery?query=setProperty(deviceId=" +
g_auth.dSUID + ")/(x-action-authcode=\"" +
g_auth.code + "\")",
callback).fail(vdc_request_failed);
var redirect_uri = encodeURIComponent(window.location.origin + window.location.pathname);
$.getJSON("/json/property/vdcquery?",
{
query: "setProperty(deviceId=" + g_auth.dSUID + ")/" +
"(x-action-authcode=\"" + g_auth.code + "\")" +
",(x-action-redirect_uri=\"" + redirect_uri + "\")"
},
callback).fail(vdc_request_failed);
return false;
}
});
......@@ -385,7 +391,7 @@ var vdc_query_device = function(device, remaining)
$.getJSON("/json/property/vdcquery?query=getProperty(deviceId=" +
device.dSUID +
")/modelUID,x-netatmo-connectionStatus,x-netatmo-username",
")/modelUID,x-netatmo-connection-status,x-netatmo-username",
callback).fail(callback);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment