| GNOME Online Accounts Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | Object Hierarchy | ||||
GoaBackendOAuth2Provider; struct GoaBackendOAuth2ProviderClass; const gchar * goa_backend_oauth2_provider_get_authorization_uri (GoaBackendOAuth2Provider *provider); const gchar * goa_backend_oauth2_provider_get_token_uri (GoaBackendOAuth2Provider *provider); const gchar * goa_backend_oauth2_provider_get_redirect_uri (GoaBackendOAuth2Provider *provider); const gchar * goa_backend_oauth2_provider_get_scope (GoaBackendOAuth2Provider *provider); const gchar * goa_backend_oauth2_provider_get_client_id (GoaBackendOAuth2Provider *provider); const gchar * goa_backend_oauth2_provider_get_client_secret (GoaBackendOAuth2Provider *provider); gchar * goa_backend_oauth2_provider_build_authorization_uri (GoaBackendOAuth2Provider *provider,const gchar *authorization_uri,const gchar *escaped_redirect_uri,const gchar *escaped_client_id,const gchar *escaped_scope); gboolean goa_backend_oauth2_provider_get_use_external_browser (GoaBackendOAuth2Provider *provider); gchar * goa_backend_oauth2_provider_get_identity_sync (GoaBackendOAuth2Provider *provider,const gchar *access_token,gchar **out_name,GCancellable *cancellable,GError **error); gchar * goa_backend_oauth2_provider_get_access_token_sync (GoaBackendOAuth2Provider *provider,GoaObject *object,gboolean force_refresh,gint *out_access_token_expires_in,GCancellable *cancellable,GError **error);
GObject +----GoaBackendProvider +----GoaBackendOAuth2Provider +----GoaBackendFacebookProvider
GoaBackendOAuth2Provider is an abstract base class for OAuth 2.0 based providers.
Subclasses must implement GoaBackendOAuth2ProviderClass.get_authorization_uri, GoaBackendOAuth2ProviderClass.get_token_uri, GoaBackendOAuth2ProviderClass.get_redirect_uri, GoaBackendOAuth2ProviderClass.get_scope, GoaBackendOAuth2ProviderClass.get_client_id, GoaBackendOAuth2ProviderClass.get_client_secret and GoaBackendOAuth2ProviderClass.get_identity_sync methods.
Additionally, the GoaBackendProviderClass.get_provider_type, GoaBackendProviderClass.get_name, GoaBackendProviderClass.build_object (this should chain up to its parent class) methods must be implemented.
Note that the GoaBackendProviderClass.add_account, GoaBackendProviderClass.refresh_account and GoaBackendProviderClass.ensure_credentials_sync methods do not need to be implemented - this type implements these methods..
typedef struct _GoaBackendOAuth2Provider GoaBackendOAuth2Provider;
The GoaBackendOAuth2Provider structure contains only private data and should only be accessed using the provided API.
struct GoaBackendOAuth2ProviderClass {
GoaBackendProviderClass parent_class;
/* pure virtual */
const gchar *(*get_authorization_uri) (GoaBackendOAuth2Provider *provider);
const gchar *(*get_token_uri) (GoaBackendOAuth2Provider *provider);
const gchar *(*get_redirect_uri) (GoaBackendOAuth2Provider *provider);
const gchar *(*get_scope) (GoaBackendOAuth2Provider *provider);
const gchar *(*get_client_id) (GoaBackendOAuth2Provider *provider);
const gchar *(*get_client_secret) (GoaBackendOAuth2Provider *provider);
gchar *(*get_identity_sync) (GoaBackendOAuth2Provider *provider,
const gchar *access_token,
gchar **out_name,
GCancellable *cancellable,
GError **error);
/* virtual but with default implementation */
gchar *(*build_authorization_uri) (GoaBackendOAuth2Provider *provider,
const gchar *authorization_uri,
const gchar *escaped_redirect_uri,
const gchar *escaped_client_id,
const gchar *escaped_scope);
gboolean (*get_use_external_browser) (GoaBackendOAuth2Provider *provider);
};
Class structure for GoaBackendOAuth2Provider.
GoaBackendProviderClass |
The parent class. |
Virtual function for goa_backend_oauth2_provider_get_authorization_uri(). |
|
Virtual function for goa_backend_oauth2_provider_get_token_uri(). |
|
Virtual function for goa_backend_oauth2_provider_get_redirect_uri(). |
|
Virtual function for goa_backend_oauth2_provider_get_scope(). |
|
Virtual function for goa_backend_oauth2_provider_get_client_id(). |
|
Virtual function for goa_backend_oauth2_provider_get_client_secret(). |
|
Virtual function for goa_backend_oauth2_provider_get_identity_sync(). |
|
Virtual function for goa_backend_oauth2_provider_build_authorization_uri(). |
|
Virtual function for goa_backend_oauth2_provider_get_use_external_browser(). |
const gchar * goa_backend_oauth2_provider_get_authorization_uri
(GoaBackendOAuth2Provider *provider);
Gets the authorization endpoint used for authenticating the user and obtaining authorization.
You should not include any parameters in the returned URI. If you
need to include additional parameters than the standard ones,
override GoaBackendOAuth2ProviderClass.build_authorization_uri -
see goa_backend_oauth2_provider_build_authorization_uri() for more
details.
This is a pure virtual method - a subclass must provide an implementation.
|
A GoaBackendOAuth2Provider. |
Returns : |
A string owned by provider - do not free. [transfer none]
|
const gchar * goa_backend_oauth2_provider_get_token_uri
(GoaBackendOAuth2Provider *provider);
Gets the token endpoint used for obtaining an access token.
You should not include any parameters in the returned URI.
This is a pure virtual method - a subclass must provide an implementation.
|
A GoaBackendOAuth2Provider. |
Returns : |
A string owned by provider - do not free. [transfer none]
|
const gchar * goa_backend_oauth2_provider_get_redirect_uri
(GoaBackendOAuth2Provider *provider);
Gets the redirect_uri used when requesting authorization.
This is a pure virtual method - a subclass must provide an implementation.
|
A GoaBackendOAuth2Provider. |
Returns : |
A string owned by provider - do not free. [transfer none]
|
const gchar * goa_backend_oauth2_provider_get_scope
(GoaBackendOAuth2Provider *provider);
Gets the scope used when requesting authorization.
This is a pure virtual method - a subclass must provide an implementation.
|
A GoaBackendOAuth2Provider. |
Returns : |
A string owned by provider - do not free. [transfer none]
|
const gchar * goa_backend_oauth2_provider_get_client_id
(GoaBackendOAuth2Provider *provider);
Gets the client_id identifying the client.
This is a pure virtual method - a subclass must provide an implementation.
|
A GoaBackendOAuth2Provider. |
Returns : |
A string owned by provider - do not free. [transfer none]
|
const gchar * goa_backend_oauth2_provider_get_client_secret
(GoaBackendOAuth2Provider *provider);
Gets the client_secret associated with the client.
This is a pure virtual method - a subclass must provide an implementation.
|
A GoaBackendOAuth2Provider. |
Returns : |
A string owned by provider - do not free. [transfer none]
|
gchar * goa_backend_oauth2_provider_build_authorization_uri (GoaBackendOAuth2Provider *provider,const gchar *authorization_uri,const gchar *escaped_redirect_uri,const gchar *escaped_client_id,const gchar *escaped_scope);
Builds the URI that can be opened in a web browser (or embedded web browser widget) to start authenticating an user.
The default implementation just returns the expected URI
(e.g. http://example.com/dialog/oauth2?response_type=code&redirect_uri=https)
- override (and chain up) if you e.g. need to to pass additional
parameters.
3A%2F2Fclient%2Eexample2Ecom%2Fcb&client_id=foo&scope=email20stuff
The authorization_uri, escaped_redirect_uri, escaped_client_id
and escaped_scope parameters originate from the result of the
the goa_backend_oauth2_provider_get_authorization_uri(), goa_backend_oauth2_provider_get_redirect_uri(), goa_backend_oauth2_provider_get_client_id()
and goa_backend_oauth2_provider_get_scope() methods with the latter
three escaped using g_uri_escape_string().
|
A GoaBackendOAuth2Provider. |
|
An authorization URI. |
|
An escaped redirect URI |
|
An escaped client id |
|
The escaped scope. |
Returns : |
An authorization URI that must be freed with g_free(). [transfer full]
|
gboolean goa_backend_oauth2_provider_get_use_external_browser
(GoaBackendOAuth2Provider *provider);
Returns whether an external browser (the users default browser) should be used for user interaction.
If an external browser is used, then the dialogs presented in
goa_backend_provider_add_account() and
goa_backend_provider_refresh_account() will show a simple "Paste
authorization code here" instructions along with an entry and
button.
This is a virtual method where the default implementation returns
FALSE.
|
A GoaBackendOAuth2Provider. |
Returns : |
TRUE if the user interaction should happen in an external
browser, FALSE to use an embedded browser widget. |
gchar * goa_backend_oauth2_provider_get_identity_sync (GoaBackendOAuth2Provider *provider,const gchar *access_token,gchar **out_name,GCancellable *cancellable,GError **error);
Method that returns the identity corresponding to
access_token.
The identity is needed because all authentication happens out of band. The only requirement is that the returned identity is unique - for example, for GoaBackendGoogleProvider the returned identity is the email address, for GoaBackendFacebookProvider it's the user name. In addition to the identity, an implementation also returns a name that is more suitable for presentation (the identity could be a GUID for example) and doesn't have to be unique.
The calling thread is blocked while the identity is obtained.
|
A GoaBackendOAuth2Provider. |
|
A valid OAuth 2.0 access token. |
|
Return location for name or NULL. [out]
|
|
A GCancellable or NULL. [allow-none]
|
|
Return location for error or NULL. |
Returns : |
The identity or NULL if error is set. The returned string
must be freed with g_free(). |
gchar * goa_backend_oauth2_provider_get_access_token_sync (GoaBackendOAuth2Provider *provider,GoaObject *object,gboolean force_refresh,gint *out_access_token_expires_in,GCancellable *cancellable,GError **error);
Synchronously gets an access token for object. The calling thread
is blocked while the operation is pending.
The resulting token is typically read from the local cache so most of the time only a local roundtrip to the storage for the token cache (e.g. gnome-keyring-daemon) is needed. However, the operation may involve refreshing the token with the service provider so a full network round-trip may be needed.
Note that multiple calls are serialized to avoid multiple outstanding requests to the service provider.
This operation may fail if e.g. unable to refresh the credentials
or if network connectivity is not available. Note that even if a
token is returned, the returned token isn't guaranteed to work -
use goa_backend_provider_ensure_credentials_sync() if you need
stronger guarantees.
|
A GoaBackendOAuth2Provider. |
|
A GoaObject. |
|
If set to TRUE, forces a refresh of the access token, if possible. |
|
Return location for how many seconds the returned token is valid for (0 if unknown) or NULL. [out]
|
|
A GCancellable or NULL. [allow-none]
|
|
Return location for error or NULL. |
Returns : |
The access token or NULL if error is set. The returned
string must be freed with g_free(). |