Return an OAuth 2.0 access token for Google Storage.
974923
def _GetAccessToken(self):
    """"""
    service_accounts = self.watcher.GetMetadata(metadata_key=self.metadata_key)
    try:
      return service_accounts[self.service_account]['token']['access_token']
    except KeyError:
      return None
642409
def get_access_token(self) -> str:
        
        if self._service_token:
            return self._service_token
        if self._app_id and self._login and self._password:
            try:
                if self.login():
                    url_params = self.auth_oauth2()
                    if 'access_token' in url_params:
                        return url_params['access_token']
            finally:
                self.close()
1113524
def get_authorization_url(self):
        """"""
        return self._format_url(
            OAUTH2_ROOT + 'authorize',
            query = {
                'response_type': 'code',
                'client_id': self.client.get('client_id', ''),
                'redirect_uri': self.client.get('redirect_uri', '')
            })
1313354
def get_access_token(self, verifier=None):
        
        try:
            url = self._get_oauth_url('access_token')

            #build request
            query = {
                'client_id': self._client_id,
                'client_secret': self._client_secret,
                'grant_type': 'authorization_code',
                'redirect_uri': self.callback,
                'code': str(verifier)
            }

            query_str = self.urlencode(query)
            request = url + '?' + query_str

            #send request
            resp = urllib.urlopen(request)
            json = simplejson.loads(resp.read())

            self.access_token = json['access_token']

            return self.access_token

        except Exception, e:
            raise FoursquareError(e)
676978
def get_access_token(self, code):
        

        payload = {'redirect_uri': self.redirect_uri,
                   'code': code,
                   'grant_type': 'authorization_code'}

        headers = self._make_authorization_headers()

        response = requests.post(self.OAUTH_TOKEN_URL, data=payload,
            headers=headers, verify=LOGIN_VERIFY_SSL_CERT)
        if response.status_code is not 200:
            raise MercedesMeAuthError(response.reason)
        token_info = response.json()
        token_info = self._add_custom_values_to_token_info(token_info)
        self._save_token_info(token_info)
        return token_info
1142928
function(code, cb) {
        var self = this;
        this.oauthClient.getToken(code, function(err, token) {
            if (err) {
                cb({
                    err: err,
                    msg: 'Error while trying to retrieve access token'
                });
                return;
            }
            self.storeToken(token);
            cb(null, {
                resp: token,
                msg: "Google auth code successfully set"
            });
        });
    }
379931
def access_token():
    """"""
    client = Client.query.filter_by(
        client_id=request.form.get('client_id')
    ).first()

    if not client:
        abort(404)

    if not client.is_confidential and \
            'client_credentials' == request.form.get('grant_type'):
        error = InvalidClientError()
        response = jsonify(dict(error.twotuples))
        response.status_code = error.status_code
        abort(response)

    # Return None or a dictionary. Dictionary will be merged with token
    # returned to the client requesting the access token.
    # Response is in application/json
    return None
714202
def request(self, method, url, params=None, **aio_kwargs):
        """"""
        oparams = {
            'oauth_consumer_key': self.consumer_key,
            'oauth_nonce': sha1(str(RANDOM()).encode('ascii')).hexdigest(),
            'oauth_signature_method': self.signature.name,
            'oauth_timestamp': str(int(time.time())),
            'oauth_version': self.version,
        }
        oparams.update(params or {})

        if self.oauth_token:
            oparams['oauth_token'] = self.oauth_token

        url = self._get_url(url)

        if urlsplit(url).query:
            raise ValueError(
                'Request parameters should be in the "params" parameter, '
                'not inlined in the URL')

        oparams['oauth_signature'] = self.signature.sign(
            self.consumer_secret, method, url,
            oauth_token_secret=self.oauth_token_secret, **oparams)
        self.logger.debug("%s %s", url, oparams)

        return self._request(method, url, params=oparams, **aio_kwargs)
1109935
def _request(self, method, url, headers=None, params=None, **aio_kwargs):
        """"""
        auth = None
        access_token = params.pop(self.access_token_key, None)
        if access_token:
            headers['Authorization'] = "Bearer %s" % access_token
        else:
            auth = BasicAuth(self.client_id, self.client_secret)

        return super(Bitbucket2Client, self)._request(
            method, url, headers=headers, params=params, auth=auth, **aio_kwargs)
827414
private RegistryAuth authForAccessToken(final AccessToken accessToken) {
    return RegistryAuth.builder()
        .username("oauth2accesstoken")
        .password(accessToken.getTokenValue())
        .build();
  }
724806
def fetch_access_token(self, code):
        
        res = self._get(
            'sns/oauth2/access_token',
            params={
                'appid': self.app_id,
                'secret': self.secret,
                'code': code,
                'grant_type': 'authorization_code'
            }
        )
        self.access_token = res['access_token']
        self.open_id = res['openid']
        self.refresh_token = res['refresh_token']
        self.expires_in = res['expires_in']
        return res
996985
public OAuthToken getToken() throws Exception {
        OAuthToken token = storageStrategy.get(getEnvKey());
        
        if (token == null || token.IsExpired()) {
            storeToken(this.root.getAuthenticationManager().createToken());
        }
        
        return storageStrategy.get(getEnvKey());
    }
1178982
def do_request_async(self, url, method='GET', headers=None, payload=None,
                       deadline=None, callback=None):
    
    if headers is None:
      headers = {}
    if 'x-goog-api-version' not in headers:
      headers['x-goog-api-version'] = '2'
    headers['accept-encoding'] = 'gzip, *'
    try:
      resp_tuple = yield super(_StorageApi, self).do_request_async(
          url, method=method, headers=headers, payload=payload,
          deadline=deadline, callback=callback)
    except urlfetch.DownloadError as e:
      raise errors.TimeoutError(
          'Request to Google Cloud Storage timed out.', e)

    raise ndb.Return(resp_tuple)
910683
function useAccessAuth() {
  return new Promise((resolve, reject) => {
    if (!defaults.accessToken) {
      reject(__generateFakeResponse__(0, '', {}, 'accessToken is missing for Access authentication'))
    }
    else {
      let details = {
        "token_type": "",
        "expires_in": 0,
        "appName": defaults.appName,
        "username": "",
        "role": "",
        "firstName": "",
        "lastName": "",
        "fullName": "",
        "regId": 0,
        "userId": null
      };
      var aToken = defaults.accessToken.toLowerCase().startsWith('bearer') ? defaults.accessToken : 'Bearer ' + defaults.accessToken;
      utils.storage.set('user', {
        token: {
          Authorization:  aToken,
          appName: defaults.appName
        },
        details: details
      });
      resolve(__generateFakeResponse__(200, 'OK', {}, details, {}));
    }
  });

}
801429
function getAccessToken($google_code) {
        // Make sure these are clear if we fail
        $this->authentication_object = FALSE;
        $this->access_token = FALSE;

        // From: https://github.com/PenguinProtocols/Basic-OpenID-Connect-Google
        // This approach gets us the openid_id from the former realm

        $token_url = "https://www.googleapis.com/oauth2/v3/token";
        $post = "code={$google_code}&client_id={$this->client_id}&client_secret={$this->client_secret}"
            . "&redirect_uri={$this->redirect}&grant_type=authorization_code";

        if ( $this->openid_realm ) {
            $post .= "&openid.realm=" . $this->openid_realm;
        }

        $response = $this->curl_post($token_url, $post);

        /* $response normally looks like this:
            {
                "access_token" : "QEX3L0Fm ... about 80 characters ... 4tLMYze617",
                "token_type" : "Bearer",
                "expires_in" : 3599,
                "id_token" : "hbGciO ... about 700 characers ... t3cE"
            }
        */

        if ($response) {
            $this->authentication_object = json_decode($response);
        }

        if (isset($this->authentication_object->refresh_token)) {
            $this->Google_RefreshToken = $this->authentication_object->refresh_token;
        }
        if (isset($this->authentication_object->access_token)) {
            $this->access_token = $this->authentication_object->access_token;
            return $this->authentication_object;
        } else {
            return FALSE;
        }
    }
258148
function getAuthenticationUrl(scopes, clientId, clientSecret, redirectUri = 'urn:ietf:wg:oauth:2.0:oob') {
	const oauth2Client = new OAuth2(
		clientId,
		clientSecret,
		redirectUri
	);
	const url = oauth2Client.generateAuthUrl({
		access_type: 'offline', // 'online' (default) or 'offline' (gets refresh_token)
		scope: scopes // If you only need one scope you can pass it as string
	});
	return url;
}
43689
def auth_uri(self):

        """"""

        return self.oauth.auth_uri(redirect_uri=self.redirect_uri, scope=self.scope)