Forum Archive

ui.webview and authentication

echen

Is it possible to pass a username password to http Basic Auth in ui.webview? thx.

ccc

You could try using the requests to get past the login screen and then use a ui.WebView to display the resulting html. It usually requires some patient tinkering to get automated logins working correctly but requests does make it easier.

# coding: utf-8

import requests, ui

def basic_login_webview(url, username, password):
    webview = ui.WebView(name=url)
    webview.load_html(requests.get(url, auth=(username, password)).text)
    return webview

webview = basic_login_webview(url='https://my.favorite.url', username='xxx', password='yyy')
webview.present()
JonB

this is likely possible in 2.0 using objc... Another option would be to use requests and then use load_html, and delegate methods, but that is somewhat annoying.

omz

You should be able to pass the username and password as part of the URL, e.g.:

import ui

v = ui.WebView()
v.load_url('http://user:passwd@httpbin.org/basic-auth/user/passwd')
v.present()
echen

Thanks for the replies, both suggestions worked.