gargle (version 1.0.0)

AuthState-class: Authorization state

Description

An AuthState object manages an authorization state, typically on behalf of a client package that makes requests to a Google API.

The How to use gargle for auth in a client package vignette describes a design for wrapper packages that relies on an AuthState object. This state can then be incorporated into the package's requests for tokens and can control the inclusion of tokens in requests to the target API.

  • api_key is the simplest way to associate a request with a specific Google Cloud Platform project. A few calls to certain APIs, e.g. reading a public Sheet, can succeed with an API key, but this is the exception.

  • app is an OAuth app associated with a specific Google Cloud Platform project. This is used in the OAuth flow, in which an authenticated user authorizes the app to access or manipulate data on their behalf.

  • auth_active reflects whether outgoing requests will be authorized by an authenticated user or are unauthorized requests for public resources. These two states correspond to sending a request with a token versus an API key, respectively.

  • cred is where the current token is cached within a session, once one has been fetched. It is generally assumed to be an instance of httr::TokenServiceAccount or httr::Token2.0 (or a subclass thereof), probably obtained via token_fetch() (or one of its constituent credential fetching functions).

An AuthState should be created through the constructor function init_AuthState(), which has more details on the arguments.

Arguments

Public fields

package

Package name.

app

An OAuth consumer application.

api_key

An API key.

auth_active

Logical, indicating whether auth is active.

cred

Credentials.

Methods

Public methods

Method new()

Create a new AuthState

Usage

AuthState$new(
  package = NA_character_,
  app = NULL,
  api_key = NULL,
  auth_active = TRUE,
  cred = NULL
)

Arguments

package

Package name.

app

An OAuth consumer application.

api_key

An API key.

auth_active

Logical, indicating whether auth is active.

cred

Credentials.

Details

For more details on the parameters, see init_AuthState()

Method print()

Print an AuthState

Usage

AuthState$print(...)

Arguments

...

Not used.

Method set_app()

Set the OAuth app

Usage

AuthState$set_app(app)

Arguments

app

An OAuth consumer application.

Method set_api_key()

Set the API key

Usage

AuthState$set_api_key(value)

Arguments

value

An API key.

Method set_auth_active()

Set whether auth is (in)active

Usage

AuthState$set_auth_active(value)

Arguments

value

Logical, indicating whether to send requests authorized with user credentials.

Method set_cred()

Set credentials

Usage

AuthState$set_cred(cred)

Arguments

cred

User credentials.

Method clear_cred()

Clear credentials

Usage

AuthState$clear_cred()

Method get_cred()

Get credentials

Usage

AuthState$get_cred()

Method has_cred()

Report if we have credentials

Usage

AuthState$has_cred()

Method clone()

The objects of this class are cloneable with this method.

Usage

AuthState$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.