I would very much like to see https support next go-round, ideally with the ability to (1) add CAs or ignore same (for self-signed certs, which I use frequently), and (2) client side cert support.
Yes, this is longhair niche stuff. It’s also needed to talk to some specific types of servers I deal with daily (f5 load balancers don’t expose a non-encrypted interface). As it stands, I have to run a proxy, and it’s “icky”, to use a technical term.
@Bortels oh it isn’t that longhair niche stuff. More and more sites are finally clueing into the fact that transmitting their data in the clear is doubleplusungood. So it is going to be a bit of an issue for lots of people in the next couple of years
Hmm. It should work with https, though I didn’t try it. It probably won’t work for self signed stuff though because it is just using iOS’ built in http connection api, which automatically errors on iffy connections. There is an API to add custom CAs though, so we could expose that.
Here is some code to use Auth for spreadsheet class. You have to call sheet:getDeviceCode() and then sheet:getAuthToken() when you have granted access with the user code that is printed. Then you can try sheet:availableSheets() to get data about your spreadsheets. Haven’t any code for refreshing tokens, but I guess I’ll soon have to learn how.
Sheet = class()
function Sheet:init()
end
function Sheet:getDeviceCode()
local deviceCodeUrl = "https://accounts.google.com/o/oauth2/device/code"
local data = "client_id=" .. CLIENT_ID .. "&scope=https://spreadsheets.google.com/feeds"
http.request(deviceCodeUrl, function (data)
local jsonData = json.decode(data)
print("user code is " .. jsonData.user_code)
saveGlobalData("deviceCode", jsonData.device_code)
saveGlobalData("userCode", jsonData.user_code)
openURL("http://www.google.com/device")
end, function (error)
print("Error " .. error)
end, {
method = "POST",
data = data,
headers = {
["Content-Type"] = "application/x-www-form-urlencoded"
}
})
end
function Sheet:getAuthToken()
local getTokenUrl = "https://accounts.google.com/o/oauth2/token"
local deviceCode = readGlobalData("deviceCode")
local data = "client_id=" .. CLIENT_ID .. "&" ..
"client_secret=" .. CLIENT_SECRET .. "&code=" ..
deviceCode .. "&grant_type=http://oauth.net/grant_type/device/1.0"
print("getAuthToken " .. data)
http.request(getTokenUrl, function (data)
print(data)
local jsonData = json.decode(data)
print("access token is " .. jsonData.access_token)
print("refresh token is " .. jsonData.refresh_token)
self.accessToken = jsonData.access_token
self.refreshToken = jsonData.refresh_token
saveGlobalData("accessToken", self.accessToken)
saveGlobalData("refreshToken", self.refreshToken)
self:availableSheets()
end, function (error)
print("Error " .. error)
end, {
method = "POST",
data = data,
headers = {
["Content-Type"] = "application/x-www-form-urlencoded"
}
})
end
function Sheet:availableSheets()
local accessToken = readGlobalData("accessToken")
local url = "https://spreadsheets.google.com/feeds/spreadsheets/private/full?" ..
"alt=json&" ..
"access_token=" .. accessToken
print("get sheets")
http.request(url, function (data)
print(data)
end)
end
function Sheet:getCells() -- from my spreadsheet with specified key
local accessToken = readGlobalData("accessToken")
local key = "0AsDhnQgjRtV2dEVPQXkwWlRTWW5CM2RkWGJPSVNnUkE"
local url = "https://spreadsheets.google.com/feeds/cells/" ..
key ..
"/od6/private/full?min-row=1&min-col=1&max-col=2&" ..
"alt=json&" ..
"access_token=" .. accessToken
print("get cells")
http.request(url, function (data)
local jsonData = json.decode(data)
for k,cell in pairs(jsonData.feed.entry) do
print(cell.title["$t"] .. " - " .. cell.content["$t"])
end
end)
end