1
// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
3
* Copyright (c) 2013-2015 Pantheon Developers (https://launchpad.net/switchboard-plug-onlineaccounts)
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public
16
* License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
20
* Authored by: Corentin Noël <corentin@elementary.io>
23
public class E.GSignonSessionPassword : E.SourceCredentialsProviderImpl {
27
manager = new Ag.Manager ();
30
public override bool can_process (E.Source source) {
32
var credentials_source = ref_credentials_source (source);
33
if (credentials_source == null) {
37
E.SourceUoa extension;
38
if (credentials_source.has_extension (E.SOURCE_EXTENSION_UOA)) {
39
var account_service = new_account_service (source);
40
if (account_service != null) {
41
var auth_data = account_service.get_auth_data ();
42
if (auth_data.get_method () == "password" && auth_data.get_mechanism () == "password") {
51
public override bool can_prompt () {
55
public override bool can_store () {
59
public override bool lookup_sync (E.Source source, GLib.Cancellable? cancellable, out E.NamedParameters out_credentials) throws GLib.Error {
60
var main_loop = new GLib.MainLoop ();
62
string password = null;
63
get_password.begin (source, (obj, res) => {
65
password = get_password.end (res);
75
debug ("Complete (ERROR - %s)", error.message);
77
debug ("Complete (SUCCESS)");
78
out_credentials = new E.NamedParameters ();
79
out_credentials.set (E.SOURCE_CREDENTIAL_PASSWORD, password);
85
private E.Source ref_credentials_source (E.Source source) {
86
var current_source = source;
87
while (current_source != null && !current_source.has_extension (E.SOURCE_EXTENSION_UOA)) {
88
var parent_id = current_source.get_parent ();
89
if (parent_id == null) {
93
current_source = get_provider ().ref_source (parent_id);
96
if (current_source != null && current_source.has_extension (E.SOURCE_EXTENSION_UOA)) {
97
return current_source;
100
if (current_source == null) {
101
current_source = get_provider ().ref_credentials_source (source);
104
return current_source;
107
private async string? get_password (E.Source source) throws GLib.Error {
109
var account_service = new_account_service (source);
110
var auth_data = account_service.get_auth_data ();
111
var identity = new Signon.Identity.from_db (auth_data.get_credentials_id ());
112
var signon_auth_session = identity.create_session ("password");
114
/* This returns a floating reference. */
115
var login_parameters = auth_data.get_login_parameters (null);
117
var session_data = yield signon_auth_session.process_async (login_parameters, "password", null);
118
var secret = session_data.lookup_value (Signon.SESSION_DATA_SECRET, GLib.VariantType.STRING);
119
if (secret == null) {
120
throw new Signon.Error.MISSING_DATA ("Signon service did not return a secret");
123
return secret.dup_string ();
129
private Ag.AccountService? new_account_service (E.Source source) throws GLib.Error {
130
E.SourceUoa extension = null;
131
var credentials_source = ref_credentials_source (source);
132
if (credentials_source != null && credentials_source.has_extension (E.SOURCE_EXTENSION_UOA)) {
133
extension = (E.SourceUoa) credentials_source.get_extension (E.SOURCE_EXTENSION_UOA);
136
if (extension == null) {
140
var account_id = extension.get_account_id ();
141
Ag.Account ag_account;
143
ag_account = manager.load_account (account_id);
148
var services = ag_account.list_services ();
149
if (services == null) {
153
return new Ag.AccountService (ag_account, services.data);
158
public static Type e_fake_module_load (GLib.TypeModule type_module) {
159
return typeof(E.GSignonSessionPassword);