ZpjAuthorizer

## ZpjAuthorizer ZpjAuthorizer — Windows Live Connect authorization interface. |

## Synopsis

    #include <zpj/zpj.h>

    struct              ZpjAuthorizerInterface;
    gboolean            zpj_authorizer_is_authorized_for_domain
                                                            (ZpjAuthorizer *iface,
                                                             ZpjAuthorizationDomain *domain);
    void                zpj_authorizer_process_call         (ZpjAuthorizer *iface,
                                                             ZpjAuthorizationDomain *domain,
                                                             RestProxyCall *call);
    void                zpj_authorizer_process_message      (ZpjAuthorizer *iface,
                                                             ZpjAuthorizationDomain *domain,
                                                             SoupMessage *message);
    gboolean            zpj_authorizer_refresh_authorization
                                                            (ZpjAuthorizer *iface,
                                                             GCancellable *cancellable,
                                                             GError **error);
    void                zpj_authorizer_refresh_authorization_async
                                                            (ZpjAuthorizer *iface,
                                                             GCancellable *cancellable,
                                                             GAsyncReadyCallback callback,
                                                             gpointer user_data);
    gboolean            zpj_authorizer_refresh_authorization_finish
                                                            (ZpjAuthorizer *iface,
                                                             GAsyncResult *res,
                                                             GError **error);

## Description

The ZpjAuthorizer interface provides a uniform way to implement authentication and authorization processes for use by ZpjSkydrive. Client code will construct a new ZpjAuthorizer instance of their choosing, such as ZpjGoaAuthorizer, and create a ZpjSkydrive with with it.

ZpjGoaAuthorizer is an implementation of ZpjAuthorizer for using authorization tokens provided by GNOME Online Accounts. It is quite possible for clients to write their own implementations. For example, on platforms that do not use GNOME Online Accounts a client might want to implement the OAuth 2.0 authorization flow itself.

It must be noted that all ZpjAuthorizer implementations must be thread safe, as methods such as `zpj_authorizer_refresh_authorization()` may be called from any thread (such as the thread performing an asynchronous ZpjSkydrive operation) at any time.

## Details

### struct ZpjAuthorizerInterface

    struct ZpjAuthorizerInterface {
      GTypeInterface parent_iface;

      gboolean    (*is_authorized_for_domain)    (ZpjAuthorizer *iface,
                                                  ZpjAuthorizationDomain *domain);
      void        (*process_call)                (ZpjAuthorizer *iface,
                                                  ZpjAuthorizationDomain *domain,
                                                  RestProxyCall *call);
      void        (*process_message)             (ZpjAuthorizer *iface,
                                                  ZpjAuthorizationDomain *domain,
                                                  SoupMessage *message);
      gboolean    (*refresh_authorization)       (ZpjAuthorizer *iface,
                                                  GCancellable *cancellable,
                                                  GError **error);
    };

Interface structure for ZpjAuthorizer. All methods should be thread safe.

GTypeInterface `parent_iface`; | The parent interface.
`is_authorized_for_domain` () | A method to check if the authorization tokens are valid for a ZpjAuthorizationDomain.
`process_call` () | A method to append authorization headers to a RestProxyCall.
`process_message` () | A method to append authorization headers to a SoupMessage. Types of messages include DELETE, GET and POST.
`refresh_authorization` () | A synchronous method to force a refresh of any authorization tokens held by the authorizer. It should return `TRUE` on success. An asynchronous version will be defined by invoking this in a thread.

### zpj_authorizer_is_authorized_for_domain ()

    gboolean            zpj_authorizer_is_authorized_for_domain
                                                            (ZpjAuthorizer *iface,
                                                             ZpjAuthorizationDomain *domain);

Whether the authorization tokens held by `iface` are valid for `domain`.

This method is thread safe.

`iface` : | A ZpjAuthorizer.
`domain` : | A ZpjAuthorizationDomain.
Returns : | `TRUE` if the tokens are valid.

### zpj_authorizer_process_call ()

    void                zpj_authorizer_process_call         (ZpjAuthorizer *iface,
                                                             ZpjAuthorizationDomain *domain,
                                                             RestProxyCall *call);

Adds the necessary authorization to `call`.

This method modifies `call` in place and is thread safe.

`iface` : | A ZpjAuthorizer.
`domain` : | An optional ZpjAuthorizationDomain object, or `NULL`. [allow-none]
`call` : | A RestProxyCall.

### zpj_authorizer_process_message ()

    void                zpj_authorizer_process_message      (ZpjAuthorizer *iface,
                                                             ZpjAuthorizationDomain *domain,
                                                             SoupMessage *message);

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.

`iface` : | A ZpjAuthorizer.
`domain` : | An optional ZpjAuthorizationDomain object, or `NULL`. [allow-none]
`message` : | A SoupMessage.

### zpj_authorizer_refresh_authorization ()

    gboolean            zpj_authorizer_refresh_authorization
                                                            (ZpjAuthorizer *iface,
                                                             GCancellable *cancellable,
                                                             GError **error);

Synchronously forces `iface` to refresh any authorization tokens held by it. See `zpj_authorizer_refresh_authorization_async()` for the asynchronous version of this call.

This method is thread safe.

`iface` : | A ZpjAuthorizer.
`cancellable` : | An optional GCancellable object, or `NULL`. [allow-none]
`error` : | An optional GError, or `NULL`. [allow-none]
Returns : | `TRUE` if the authorizer now has a valid token.

### zpj_authorizer_refresh_authorization_async ()

    void                zpj_authorizer_refresh_authorization_async
                                                            (ZpjAuthorizer *iface,
                                                             GCancellable *cancellable,
                                                             GAsyncReadyCallback callback,
                                                             gpointer user_data);

Asynchronously forces `iface` to refresh any authorization tokens held by it. See `zpj_authorizer_refresh_authorization()` for the synchronous version of this call.

When the operation is finished, `callback` will be called. You can then call `zpj_authorizer_refresh_authorization_finish()` to get the result of the operation.

This method is thread safe.

`iface` : | A ZpjAuthorizer.
`cancellable` : | An optional GCancellable object, or `NULL`. [allow-none]
`callback` : | A GAsyncReadyCallback to call when the request is satisfied. [scope async]
`user_data` : | The data to pass to `callback`. [closure]

### zpj_authorizer_refresh_authorization_finish ()

    gboolean            zpj_authorizer_refresh_authorization_finish
                                                            (ZpjAuthorizer *iface,
                                                             GAsyncResult *res,
                                                             GError **error);

Finishes an asynchronous operation started with `zpj_authorizer_refresh_authorization_async()`.

`iface` : | A ZpjAuthorizer.
`res` : | A GAsyncResult.
`error` : | An optional GError, or `NULL`. [allow-none]
Returns : | `TRUE` if the authorizer now has a valid token.