NAME

Google::Ads::GoogleAds::OAuth2ApplicationsHandler

DESCRIPTION

A concrete implementation of Google::Ads::GoogleAds::Common::OAuth2BaseHandler and Google::Ads::GoogleAds::Common::OAuthApplicationsHandlerInterface that supports OAuth2 for Web/Desktop applications and defines the scope required to access the Google Ads API server.

See https://developers.google.com/identity/protocols/oauth2 for details of the protocol.

ATTRIBUTES

Each of these attributes can be set via Google::Ads::GoogleAds::OAuth2ApplicationsHandler->new().

Alternatively, there is a get_ and set_ method associated with each attribute for retrieving or setting them dynamically.

api_client

A reference to the API client used to handle the API requests.

client_id

OAuth2 client id obtained from the Google APIs console.

client_secret

OAuth2 client secret obtained from the Google APIs console.

access_type

OAuth2 access type to be requested when following the authorization flow. It defaults to offline but it can be set to online.

prompt

OAuth2 prompt to be used when following the authorization flow. It defaults to consent.

redirect_uri

Redirect URI as set for you in the Google APIs console, to which the authorization flow will callback with the authorization code. Defaults to urn:ietf:wg:oauth:2.0:oob for the desktop applications flow.

access_token

Stores an OAuth2 access token after the authorization flow is followed or for you to manually set it in case you had it previously stored. If this is manually set this handler will verify its validity before preparing a request.

refresh_token

Stores an OAuth2 refresh token in case of an offline "access_type" is requested. It is automatically used by the handler to request new access tokens, i.e. when they are expired or found invalid.

additional_scopes

Stores additional OAuth2 scopes as a comma-separated string. These scopes define which services the tokens are allowed to access, e.g. https://www.googleapis.com/auth/analytics.

METHODS

initialize

Initializes the handler with the API client object and the properties such as client_id and client_secret, used for generating authorization requests.

Parameters

  • A required api_client with a reference to the API client object handling the requests against the API.

  • A hash reference with the following keys:

    {
      clientId         => "client-id",
      clientSecret     => "client-secret",
      accessType       => "access-type",
      approvalPrompt   => "approval-prompt",
      redirectUri      => "redirect-uri",
      accessToken      => "access-token",
      refreshToken     => "refresh-token",
      additionalScopes => "additional-scopes",
    }

    Refer to the documentation of the properties as "client_id", "client_secret", "access_type", "prompt", "redirect_uri", "access_token", "refresh_token" and "additional_scopes".

prepare_request

Refer to Google::Ads::GoogleAds::Common::AuthHandlerInterface documentation of this method.

is_auth_enabled

Refer to Google::Ads::GoogleAds::Common::AuthHandlerInterface documentation of this method.

get_authorization_url

Refer to Google::Ads::GoogleAds::Common::OAuthApplicationsHandlerInterface documentation of this method.

issue_access_token

Refer to Google::Ads::GoogleAds::Common::OAuthApplicationsHandlerInterface documentation of this method.

_scope

Method defined by Google::Ads::GoogleAds::Common::OAuth2BaseHandler and implemented in this class to return the required OAuth2 scopes as an array.

_refresh_access_token

Method defined by Google::Ads::GoogleAds::Common::OAuth2BaseHandler and implemented in this class to refresh the stored OAuth2 access token.

__formatted_scopes

Private method to return the OAuth2 scopes as a list of encoded URLs separated by pluses. This is the format expected when sending the OAuth2 request in a URL.

Returns

The encoded URL string of OAuth2 scopes separated by pluses.

LICENSE AND COPYRIGHT

Copyright 2019 Google LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

REPOSITORY INFORMATION

$Rev: $
$LastChangedBy: $
$Id: $