~ubuntu-branches/ubuntu/raring/empathy/raring-updates

« back to all changes in this revision

Viewing changes to libempathy/empathy-goa-auth-handler.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-11-14 09:37:59 UTC
  • mfrom: (1.1.108)
  • Revision ID: package-import@ubuntu.com-20121114093759-6j9gbp2lxdaquind
Tags: 3.6.2-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
182
182
            auth_cb, data);
183
183
        break;
184
184
 
 
185
      case EMPATHY_SASL_MECHANISM_GOOGLE:
 
186
        empathy_sasl_auth_google_async (data->channel,
 
187
            goa_account_get_identity (goa_object_peek_account (data->goa_object)),
 
188
            access_token, auth_cb, data);
 
189
        break;
 
190
 
185
191
      default:
186
192
        g_assert_not_reached ();
187
193
    }
190
196
}
191
197
 
192
198
static void
 
199
got_password_passwd_cb (GObject *source,
 
200
    GAsyncResult *result,
 
201
    gpointer user_data)
 
202
{
 
203
  GoaPasswordBased *password = (GoaPasswordBased *) source;
 
204
  AuthData *data = user_data;
 
205
  gchar *passwd;
 
206
  GError *error = NULL;
 
207
 
 
208
  if (!goa_password_based_call_get_password_finish (password,
 
209
          &passwd, result, &error))
 
210
    {
 
211
      DEBUG ("Failed to get password: %s", error->message);
 
212
      fail_auth (data);
 
213
      g_clear_error (&error);
 
214
      return;
 
215
    }
 
216
 
 
217
  DEBUG ("Got password for %s", tp_proxy_get_object_path (data->account));
 
218
 
 
219
  empathy_sasl_auth_password_async (data->channel, passwd, auth_cb, data);
 
220
  g_free (passwd);
 
221
}
 
222
 
 
223
static void
193
224
ensure_credentials_cb (GObject *source,
194
225
    GAsyncResult *result,
195
226
    gpointer user_data)
197
228
  AuthData *data = user_data;
198
229
  GoaAccount *goa_account = (GoaAccount *) source;
199
230
  GoaOAuth2Based *oauth2;
 
231
  GoaPasswordBased *password;
 
232
  EmpathySaslMechanism mech;
 
233
  gboolean supports_password;
200
234
  gint expires_in;
201
235
  GError *error = NULL;
202
236
 
209
243
      return;
210
244
    }
211
245
 
212
 
  /* We support only oaut2 */
 
246
  /* We prefer oauth2, if available */
213
247
  oauth2 = goa_object_get_oauth2_based (data->goa_object);
214
 
  if (oauth2 == NULL)
215
 
    {
216
 
      DEBUG ("GoaObject does not implement oauth2");
217
 
      fail_auth (data);
218
 
      return;
219
 
    }
220
 
 
221
 
  DEBUG ("Goa daemon has credentials for %s, get the access token",
222
 
      tp_proxy_get_object_path (data->account));
223
 
 
224
 
  goa_oauth2_based_call_get_access_token (oauth2, NULL,
225
 
      got_oauth2_access_token_cb, data);
226
 
 
227
 
  g_object_unref (oauth2);
 
248
  mech = empathy_sasl_channel_select_mechanism (data->channel);
 
249
  if (oauth2 != NULL && mech != EMPATHY_SASL_MECHANISM_PASSWORD)
 
250
    {
 
251
      DEBUG ("Goa daemon has credentials for %s, get the access token",
 
252
          tp_proxy_get_object_path (data->account));
 
253
 
 
254
      goa_oauth2_based_call_get_access_token (oauth2, NULL,
 
255
          got_oauth2_access_token_cb, data);
 
256
 
 
257
      g_object_unref (oauth2);
 
258
      return;
 
259
    }
 
260
 
 
261
  /* Else we use the password */
 
262
  password = goa_object_get_password_based (data->goa_object);
 
263
  supports_password = empathy_sasl_channel_supports_mechanism (data->channel,
 
264
      "X-TELEPATHY-PASSWORD");
 
265
  if (password != NULL && supports_password)
 
266
    {
 
267
      DEBUG ("Goa daemon has credentials for %s, get the password",
 
268
          tp_proxy_get_object_path (data->account));
 
269
 
 
270
      /* arg_id is currently unused */
 
271
      goa_password_based_call_get_password (password, "", NULL,
 
272
          got_password_passwd_cb, data);
 
273
 
 
274
      g_object_unref (password);
 
275
      return;
 
276
    }
 
277
 
 
278
  DEBUG ("GoaObject does not implement oauth2 or password");
 
279
  fail_auth (data);
228
280
}
229
281
 
230
282
static void
351
403
 
352
404
  mech = empathy_sasl_channel_select_mechanism (channel);
353
405
  return mech == EMPATHY_SASL_MECHANISM_FACEBOOK ||
354
 
      mech == EMPATHY_SASL_MECHANISM_WLM;
 
406
      mech == EMPATHY_SASL_MECHANISM_WLM ||
 
407
      mech == EMPATHY_SASL_MECHANISM_GOOGLE ||
 
408
      mech == EMPATHY_SASL_MECHANISM_PASSWORD;
355
409
}