summaryrefslogtreecommitdiff
path: root/gfbgraph/gfbgraph-authorizer.c
blob: 2ce23418383f2e41fd3947b04354795aa9340598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*-  */
/*
 * libgfbgraph - GObject library for Facebook Graph API
 * Copyright (C) 2013 Álvaro Peña <alvaropg@gmail.com>
 *               2020 Leesoo Ahn <yisooan@fedoraproject.org>
 *
 * GFBGraph is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * GFBGraph is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GFBGraph.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * SECTION:gfbgraph-authorizer
 * @title: GFBGraphAuthorizer
 * @short_description: Facebook Graph API authorization interface.
 * @include: gfbgraph/gfbgraph.h
 *
 * #GFBGraphAuthorizer interface provides a uniform way to implement authentication
 * and authorization process for use by GFBGraph functions.
 **/

#include "gfbgraph-authorizer.h"

G_DEFINE_INTERFACE (GFBGraphAuthorizer, gfbgraph_authorizer, G_TYPE_OBJECT);

static void
gfbgraph_authorizer_default_init (GFBGraphAuthorizerInterface *iface)
{
}

/**
 * gfbgraph_authorizer_process_call:
 * @iface: A #GFBGraphAuthorizer.
 * @call: A #RestProxyCall.
 *
 * Adds the necessary authorization to @call.
 *
 * This method modifies @call in place and is thread safe.
 */
void
gfbgraph_authorizer_process_call (GFBGraphAuthorizer *iface,
                                  RestProxyCall      *call)
{
  g_return_if_fail (GFBGRAPH_IS_AUTHORIZER (iface));

  GFBGRAPH_AUTHORIZER_GET_IFACE (iface)->process_call (iface, call);
}

/**
 * gfbgraph_authorizer_process_message:
 * @iface: A #GFBGraphAuthorizer.
 * @message: A #SoupMessage.
 *
 * Adds the necessary authorization to @message. The type of @message
 * can be DELETE, GET and POST.
 *
 * This method modifies @message in place and is thread safe.
 */
void
gfbgraph_authorizer_process_message (GFBGraphAuthorizer *iface,
                                     SoupMessage        *message)
{
  g_return_if_fail (GFBGRAPH_IS_AUTHORIZER (iface));

  GFBGRAPH_AUTHORIZER_GET_IFACE (iface)->process_message (iface, message);
}

/**
 * gfbgraph_authorizer_refresh_authorization:
 * @iface: A #GFBGraphAuthorizer.
 * @cancellable: (allow-none): An optional #GCancellable object, or %NULL.
 * @error: (allow-none): An optional #GError, or %NULL.
 *
 * Synchronously forces @iface to refresh any authorization tokens
 * held by it.
 *
 * This method is thread safe.
 *
 * Returns: %TRUE if the authorizer now has a valid token.
 */
gboolean
gfbgraph_authorizer_refresh_authorization (GFBGraphAuthorizer  *iface,
                                           GCancellable        *cancellable,
                                           GError             **error)
{
  g_return_val_if_fail (GFBGRAPH_IS_AUTHORIZER (iface), FALSE);

  return GFBGRAPH_AUTHORIZER_GET_IFACE (iface)->refresh_authorization (iface,
                                                                       cancellable,
                                                                       error);
}