GDAL

Public Types | Public Member Functions | List of all members
GOA2Manager Class Reference

Manager of Google OAuth2 authentication. More...

`#include <cpl_http.h>`

## Public Types
enum | AuthMethod { NONE, GCE, ACCESS_TOKEN_FROM_REFRESH, SERVICE_ACCOUNT }
| Authentication method.

## Public Member Functions
| GOA2Manager ()
| Constructor.
bool | SetAuthFromGCE (CSLConstList papszOptions)
| Specifies that the authentication will be done using the local credentials of the current Google Compute Engine VM. More...
bool | SetAuthFromRefreshToken (const char *pszRefreshToken, const char *pszClientId, const char *pszClientSecret, CSLConstList papszOptions)
| Specifies that the authentication will be done using the OAuth2 client id method. More...
bool | SetAuthFromServiceAccount (const char *pszPrivateKey, const char *pszClientEmail, const char *pszScope, CSLConstList papszAdditionalClaims, CSLConstList papszOptions)
| Specifies that the authentication will be done using the OAuth2 service account method. More...
AuthMethod | GetAuthMethod () const
| Returns the authentication method.
const char * | GetBearer () const
| Return the access token. More...
const CPLString & | GetPrivateKey () const
| Returns private key for SERVICE_ACCOUNT method.
const CPLString & | GetClientEmail () const
| Returns client email for SERVICE_ACCOUNT method.

## Detailed Description

Manager of Google OAuth2 authentication.

This class handles different authentication methods and handles renewal of access token.

Since
  GDAL 2.3

## Member Function Documentation

## ◆ GetBearer()

const char * GOA2Manager::GetBearer | ( |  | ) | const

Return the access token.

This is the value to append to a "Authorization: Bearer " HTTP header.

A network request is issued only if no access token has been yet queried, or if its expiration delay has been reached.

Returns
  the access token, or NULL in case of error.

## ◆ SetAuthFromGCE()

bool GOA2Manager::SetAuthFromGCE | ( | CSLConstList | papszOptions | ) |

Specifies that the authentication will be done using the local credentials of the current Google Compute Engine VM.

This queries http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token

Parameters

  papszOptions | NULL terminated list of options.

Returns
  true in case of success (no network access is done at this stage)

## ◆ SetAuthFromRefreshToken()

bool GOA2Manager::SetAuthFromRefreshToken | ( | const char * | pszRefreshToken,
|  | const char * | pszClientId,
|  | const char * | pszClientSecret,
|  | CSLConstList | papszOptions
| ) |  |

Specifies that the authentication will be done using the OAuth2 client id method.

See http://code.google.com/apis/accounts/docs/OAuth2.html

Parameters

  pszRefreshToken | refresh token. Must be non NULL.
  pszClientId | client id (may be NULL, in which case the GOA2_CLIENT_ID configuration option is used)
  pszClientSecret | client secret (may be NULL, in which case the GOA2_CLIENT_SECRET configuration option is used)
  papszOptions | NULL terminated list of options, or NULL.

Returns
  true in case of success (no network access is done at this stage)

## ◆ SetAuthFromServiceAccount()

bool GOA2Manager::SetAuthFromServiceAccount | ( | const char * | pszPrivateKey,
|  | const char * | pszClientEmail,
|  | const char * | pszScope,
|  | CSLConstList | papszAdditionalClaims,
|  | CSLConstList | papszOptions
| ) |  |

Specifies that the authentication will be done using the OAuth2 service account method.

See https://developers.google.com/identity/protocols/OAuth2ServiceAccount

Parameters

  pszPrivateKey | RSA private key. Must be non NULL.
  pszClientEmail | client email. Must be non NULL.
  pszScope | authorization scope. Must be non NULL.
  papszAdditionalClaims | NULL terminate list of additional claims, or NULL.
  papszOptions | NULL terminated list of options, or NULL.

Returns
  true in case of success (no network access is done at this stage)

The documentation for this class was generated from the following files:

- cpl_http.h
- cpl_google_oauth2.cpp