bryanl / webbrowser

go library for opening URLs in web browsers
MIT License
10 stars 1 forks source link

when opening a URL that requires authentication, web browser will open the redirect #2

Open igalic opened 8 years ago

igalic commented 8 years ago

This seems to be primarily on linux when trying to xdg-open a url that requires authentication before access, xdg-open will use whatever that URL redirects to. e.g.:

igalic@levix ~> curl -I  https://cloud.digitalocean.com/settings/api/tokens/new
HTTP/1.1 302 Found
Server: cloudflare-nginx
Date: Wed, 30 Mar 2016 19:57:13 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Set-Cookie: __cfduid=df9cfd98f8b2674008344407500bd15eb1459367833; expires=Thu, 30-Mar-17 19:57:13 GMT; path=/; domain=.digitalocean.com; HttpOnly
Status: 302 Found
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Location: https://cloud.digitalocean.com/login
Cache-Control: no-cache
Set-Cookie: _digitalocean2_session_v2=VlBrR01Rc2orZllDNGNrRVZYNCsxa21JZVRwbUNwbkxCdmFtV3RyT1RQRUxwTjhnNUZ6WER1WEc0cGNGcnBXbFVXZFJmVUxkUlVvQXpCb2F3aGViK2UrN0pFRWI1VU9FNFJMTExHTFhUcWZvdmE3emw3NDQ2OHFnS2ZoV29sTm5kYU9CUXg3NXpnUkUyK2l1Q2dndUdnN2w3WU4yaVJqTjhiUEFKTWZ2UUJNZkhtRmVYN09zVkw3TEdMa0Q2RFdUYU1nZGdrUk5EVGl1OFpQRnYxNElDTmFVTnRRbFRhUHVsWUtReWxMdUZUK3FxZFo3eEduUFlNUGV3Mmt5ZW5ac2lHdUFYRkIwVytDamkwa2RITUx4UFIzblF2c3V5Rzd6dmFpaDFzTWthRlNBVkJsRDFVK00xWlYrQTZaSEV5Q2RaYjh5VVM4VnQrZWpuMHpmVnpDQzRvcENkaURpYWE4bXlycE5jb1lqdG12OU0rdTRZQ1dpbllxakZpTkJsaUJkUFIyN1hJTDlac3FxVEJFcEk4NW9ZTGhScCtaS0RwMHM3SFpZWFkyakhET1FlNXVVZU5udVRMWWVJNlNGOHVVRzIxaVllRnBXbVl3RXVVQklpWTdWRTlKZHlBZDU2Y1dtT1VwM1c0WFkxd2x4MXpvRC92cXdwYnRwTzZpTnhNWGdoNUt0RkpFQ2l6eWFrdVJidmpvd1YyTE05emN6bjVNcXh5TjBBQXVXN1NrPS0tMWZOQUs1SHdNb1huWWRTRSthRlVBZz09--5d07ef57ed0e672cef20800db2dfc0e6a8a54a95; path=/; secure; HttpOnly
X-Request-Id: d27bbbfe-2067-4a2a-9e39-a59b805d265c
X-Runtime: 0.044310
Strict-Transport-Security: max-age=31536000
CF-RAY: 28be211e9ad00c89-AMS

igalic@levix ~> 

that means, that when trying to xdg-open https://cloud.digitalocean.com/settings/api/tokens/new - it will actually open https://cloud.digitalocean.com/login

igalic commented 8 years ago

apparently this isn't an xdg-utils bug: https://bugs.freedesktop.org/buglist.cgi?bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&bug_status=NEEDINFO&bug_status=PLEASETEST&component=xdg-utils&query_format=advanced&short_desc=redirect&short_desc_type=allwordssubstr or at least no one has noticed it so far.

bryanl commented 8 years ago

I'm going to be testing this out tomorrow. I'll make sure to post back here with my findings.

igalic commented 8 years ago

i've traced this down to kde-open5, now let's see what that does


of course that only calls KRun::runService()

bryanl commented 8 years ago

Would you mind describing your setup, so I can help you diagnose this a bit more. I've verified it works on a fresh Ubuntu 14.04.

igalic commented 8 years ago

This is kubuntu 16.04 with its latest plasma desktop

igalic commented 8 years ago

update: from https://quickgit.kde.org/?p=kio.git&a=blob&h=b9b232dc80e9fa9b47f65203aa72b52280124fc1&hb=19fd3c456037c9cd7f762b174172de085fd53673&f=src%2Fwidgets%2Fkrun.cpp (line 104++)

static QString schemeHandler(const QString &protocol)
{
    // We have up to two sources of data, for protocols not handled by kioslaves (so called "helper") :
    // 1) the exec line of the .protocol file, if there's one
    // 2) the application associated with x-scheme-handler/<protocol> if there's one

    // If both exist, then:
    //  A) if the .protocol file says "launch an application", then the new-style handler-app has priority
    //  B) but if the .protocol file is for a kioslave (e.g. kio_http) then this has priority over
    //     firefox or chromium saying x-scheme-handler/http. Gnome people want to send all HTTP urls
    //     to a webbrowser, but we want mimetype-determination-in-calling-application by default
    //     (the user can configure a BrowserApplication though)

    const KService::Ptr service = KMimeTypeTrader::self()->preferredService(QLatin1String("x-scheme-handler/") + protocol);
    if (service) {
        return service->exec(); // for helper protocols, the handler app has priority over the hardcoded one (see A above)
    }
    Q_ASSERT(KProtocolInfo::isHelperProtocol(protocol));
    return KProtocolInfo::exec(protocol);
}

so kde tries to figure out if the resulting url is an image, or a PDF, or whatever, before trying to open it in Gwenview, or Okular, or giving up and opening it in a browser. This is not so good in our case. It would be nice if we could override that.

bryanl commented 8 years ago

@igalic I'm working out a solution to make this work with Kubuntu right now.

igalic commented 8 years ago

oh, wow… i haven't had time in almost a month for github gardening ._. thank you @bryanl :purple_heart:!