def activate_connection( meta, builder, verifier, lets_connect): # type: (Metadata, Gtk.builder, str, bool) -> None """do the actual connecting action""" logger.info("Connecting to {}".format(meta.display_name)) disconnect_all() _, name = get_brand(lets_connect) notification = init_notify(lets_connect) notify(notification, "{} connecting...".format(name), "Connecting to '{}'".format(meta.display_name)) try: if not meta.token: logger.error("metadata for {} doesn't contain oauth2 token".format( meta.uuid)) connect_provider(meta.uuid) else: oauth = oauth_from_token(meta=meta, lets_connect=lets_connect) thread_helper(lambda: _auth_check( oauth, meta, verifier, builder, lets_connect=lets_connect)) except Exception as e: switch = builder.get_object('connect-switch') GLib.idle_add(switch.set_active, False) window = builder.get_object('eduvpn-window') error_helper(window, "can't enable connection", "{}: {}".format(type(e).__name__, str(e))) raise
def _phase1_background(meta, dialog, verifier, builder): try: logger.info("starting token obtaining in background") r = get_instance_info(instance_uri=meta.instance_base_uri, verifier=verifier) meta.api_base_uri, meta.authorization_endpoint, meta.token_endpoint = r except Exception as e: GLib.idle_add(lambda: error_helper(dialog, "Can't fetch instance info", "{}".format(str(e)))) GLib.idle_add(lambda: dialog.hide()) raise meta.refresh_token() if not meta.token: code_verifier = gen_code_verifier() port = get_open_port() try: oauth = create_oauth_session(port, auto_refresh_url=meta.token_endpoint) auth_url = get_auth_url(oauth, code_verifier, meta.authorization_endpoint) except Exception as e: GLib.idle_add(lambda: error_helper( dialog, "Can't create oauth session", "{}".format(str(e)))) GLib.idle_add(lambda: dialog.hide()) raise else: GLib.idle_add(lambda: _phase1_callback( meta, port, code_verifier, oauth, auth_url, dialog, builder)) else: logger.info("we already have a token, skipping browser step") oauth = oauth_from_token(meta=meta) GLib.idle_add(lambda: _phase2_callback( meta=meta, oauth=oauth, dialog=dialog, builder=builder))
def activate_connection(meta, builder): """do the actual connecting action""" logger.info("Connecting to {}".format(meta.display_name)) notify("eduVPN connecting...", "Connecting to '{}'".format(meta.display_name)) try: if not meta.token: logger.error("metadata for {} doesn't contain oauth2 token".format(meta.uuid)) else: oauth = oauth_from_token(meta=meta) config = get_profile_config(oauth, meta.api_base_uri, meta.profile_id) meta.config = config update_config_provider(meta) if datetime.now() > datetime.fromtimestamp(meta.token['expires_at']): logger.info("key pair is expired") cert, key = create_keypair(oauth, meta.api_base_uri) update_keys_provider(meta.uuid, cert, key) connect_provider(meta.uuid) except Exception as e: switch = builder.get_object('connect-switch') GLib.idle_add(switch.set_active, False) window = builder.get_object('eduvpn-window') error_helper(window, "can't enable connection", "{}: {}".format(type(e).__name__, str(e))) raise
def _phase1_background(meta, dialog, verifier, builder, force_token_refresh, lets_connect): # type: (Metadata, Any, str, Gtk.builder, Optional[bool], bool) -> None try: logger.info(u"starting token obtaining in background") r = get_instance_info(instance_uri=meta.instance_base_uri, verifier=verifier) meta.api_base_uri, meta.authorization_endpoint, meta.token_endpoint = r # type: ignore except Exception as e: error = e GLib.idle_add(lambda: error_helper(dialog, "Can't fetch instance info", "{}".format(str(error)))) GLib.idle_add(lambda: dialog.hide()) raise meta.refresh_token() if not meta.token and not force_token_refresh: # lets see if other profiles already have a token we can use token = reuse_token_from_base_uri(meta.instance_base_uri) if token: meta.token = token if not meta.token: code_verifier = gen_code_verifier() port = get_open_port() try: oauth = create_oauth_session(port, lets_connect=lets_connect, auto_refresh_url=meta.token_endpoint) auth_url, state = get_auth_url( oauth, code_verifier, meta.authorization_endpoint) # type: ignore except Exception as e: error = e GLib.idle_add(lambda: error_helper( dialog, "Can't create oauth session", "{}".format(str(error)))) GLib.idle_add(lambda: dialog.hide()) raise else: GLib.idle_add(lambda: _phase1_callback(meta, port, code_verifier, oauth, auth_url, dialog, builder, state, lets_connect=lets_connect)) else: logger.info(u"we already have a token, skipping browser step") oauth = oauth_from_token(meta=meta, lets_connect=lets_connect) GLib.idle_add(lambda: _phase2_callback(meta=meta, oauth=oauth, dialog=dialog, builder=builder, lets_connect=lets_connect))
def _background(meta, builder, verifier, lets_connect): # type: (Metadata, Gtk.builder, str, bool) -> None label = builder.get_object('messages-label') window = builder.get_object('eduvpn-window') try: oauth = oauth_from_token(meta=meta, lets_connect=lets_connect) except Exception as e: error = e GLib.idle_add(lambda: error_helper( window, "Can't reconstruct OAuth2 session", (str(error)))) print(meta) raise text = "" try: messages_user = list(user_messages(oauth, meta.api_base_uri)) messages_system = list(system_messages(oauth, meta.api_base_uri)) info = user_info(oauth, meta.api_base_uri) except EduvpnAuthException: GLib.idle_add(lambda: reauth(meta=meta, verifier=verifier, builder=builder, lets_connect=lets_connect)) except Exception as e: error = e GLib.idle_add(lambda: error_helper(window, "Can't fetch user messages", str(error))) raise else: if info['is_disabled']: GLib.idle_add(lambda: error_helper( window, "This account has been disabled", "")) for date_time, type_, message in messages_user: logger.info("user message at {}: {}".format(date_time, message)) text += "<b><big>{}</big></b>\n".format(date_time) text += "<small><i>user, {}</i></small>\n".format(type_) text += "{}\n\n".format(message) for date_time, type_, message in messages_system: logger.info("system message at {}: {}".format(date_time, message)) text += "<b><big>{}</big></b>\n".format(date_time) text += "<small><i>system, {}</i></small>\n".format(type_) text += "{}\n\n".format(message) GLib.idle_add(lambda: label.set_markup(text))