https support

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.

We will have to look into it some more.

You know what? It does, you’re right.

Problem for me is the two places I’ve targeted so far use self-signed certs. Custom CA support would do the trick. Thank you for considering it.

Awesome, and @Dylan I would love it if you exposed the API to add custom CAs.

…and I can’t do OAuth stuff with some services without https support :frowning:

Anyone have some OAuth code to share? :slight_smile:

Well ok, now I have! :slight_smile:

I used Auth 2.0 for Devices for Google Spreadsheets. I don’t know if that’s ok, but can’t get access to the browser to use the other variants. https://developers.google.com/accounts/docs/OAuth2ForDevices

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