Retrieve an access token for the scopes supplied.
506357
public function authenticateForScope($scopes)
  {
    if ($this->token && $this->tokenScopes == $scopes) {
      return $this->token;
    }

    $cacheKey = self::CACHE_PREFIX;
    if (is_string($scopes)) {
      $cacheKey .= $scopes;
    } else if (is_array($scopes)) {
      $cacheKey .= implode(":", $scopes);
    }

    $this->token = $this->client->getCache()->get($cacheKey);
    if (!$this->token) {
      $this->retrieveToken($scopes, $cacheKey);
    } else if ($this->token['expiration_time'] < time()) {
      $this->client->getCache()->delete($cacheKey);
      $this->retrieveToken($scopes, $cacheKey);
    }

    $this->tokenScopes = $scopes;
    return $this->token;
  }
15696
def get_owner_access_token(self):
        """"""
        from .database import Session
        db_session = Session.object_session(self)
        owner = db_session.query(User).filter_by(
            id_=self.owner_id).first()
        return owner.access_token
1101930
def get_scopes_information(self):
        
        scopes = StandardScopeClaims.get_scopes_info(self.params['scope'])
        if settings.get('OIDC_EXTRA_SCOPE_CLAIMS'):
            scopes_extra = settings.get(
                'OIDC_EXTRA_SCOPE_CLAIMS', import_str=True).get_scopes_info(self.params['scope'])
            for index_extra, scope_extra in enumerate(scopes_extra):
                for index, scope in enumerate(scopes[:]):
                    if scope_extra['scope'] == scope['scope']:
                        del scopes[index]
        else:
            scopes_extra = []

        return scopes + scopes_extra
190297
def check_scope(self, token, request):
        http_method = request.method
        if not hasattr(self, http_method):
            raise OAuthError("HTTP method is not recognized")
        required_scopes = getattr(self, http_method)
        # a None scope means always allowed
        if required_scopes is None:
            return True
        
        # for non iterable types
        if isinstance(required_scopes, six.string_types):
            if token.allow_scopes(required_scopes.split()):
                return [required_scopes]
            return []
        allowed_scopes = []
        try:
            for scope in required_scopes:
                if token.allow_scopes(scope.split()):
                    allowed_scopes.append(scope)
        except:
            raise Exception('Invalid required scope values')
        else:
            return allowed_scopes
642740
private static Credential getCredentialFromAccessTokenProvider(
      AccessTokenProvider accessTokenProvider, Collection<String> scopes)
      throws IOException, GeneralSecurityException {
    Preconditions.checkArgument(
        accessTokenProvider.getAccessToken() != null, "Access Token cannot be null!");
    GoogleCredential credential =
        GoogleCredentialWithAccessTokenProvider.fromAccessTokenProvider(
            Clock.SYSTEM, accessTokenProvider);
    // TODO: credential.createScoped does nothing at the moment, since
    //  GoogleCredentialWithAccessTokenProvider never sets the serviceAccountPrivateKey.
    //  The AccessTokenProvider interface does not provide a mechanism to return a private key,
    //  and scopes cannot be sent down to the AccessTokenProvider
    //  so they're essentially ignored at the moment.
    return credential.createScoped(scopes);
  }
417674
def _get_scope_with_symbol(self, name):
        """"""
        scope = self
        while True:
            parent = scope.get_enclosing_scope()
            if parent is None:
                return

            if name in parent.symbols:
                return parent

            scope = parent
1053892
def _make_token_async(scopes, service_account_id):
  
  rpc = app_identity.create_rpc()
  app_identity.make_get_access_token_call(rpc, scopes, service_account_id)
  token, expires_at = yield rpc
  raise ndb.Return((token, expires_at))
1297797
private String scopesToString(Auth.UrlCodex urlCodex) {
        if (scopes == null || scopes.length == 0) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        boolean needsSeparator = false;
        for (String scope : scopes) {
            if (needsSeparator) {
                sb.append(scopeDelimiter);
            }
            needsSeparator = true;

            // Use the URL codex to encode each scope, if provided.
            sb.append(urlCodex == null ? scope : urlCodex.encode(scope));
        }
        return sb.toString();
    }
1195177
def _request(self, base_url, client_id, client_secret,
                 parameters, **kwargs):
        """"""
        logging.debug('Getting an OAuth token for client "%s" with scope "%s"',
                      client_id, parameters.get('scope'))
        headers = {'Content-Type': 'application/x-www-form-urlencoded',
                   'Accept': 'application/json'}

        api = API(base_url,
                  auth_username=client_id,
                  auth_password=client_secret,
                  **kwargs)
        endpoint = api.auth.token

        response = yield endpoint.post(body=urllib.urlencode(parameters),
                                       request_timeout=60,
                                       headers=headers)

        logging.debug('Received token: %s', response.get('access_token'))
        raise Return(response)
393186
def auth_url(self, scope):
        """"""
        params = {
            'response_type': 'code',
            'client_id': self.__client_id,
            'redirect_uri': self.__redirect_uri,
            'scope': scope
        }

        if self.__state is not None:
            params['state'] = self.__state

        return settings.AUTH_ENDPOINT + '/authorize?' + urllib.urlencode(params)
1155681
def access_token(self):
        """"""
        if self.cache_token:
            return self.access_token_ or \
                   self._resolve_credential('access_token')
        return self.access_token_
668233
def retrieve_token(self, token):
        
        headers = self.client._get_private_headers()
        endpoint = '/tokens/{}'.format(token)
        return self.client._get(self.client.URL_BASE + endpoint, headers=headers)
790410
public static Credential credential(
      AccessTokenProvider accessTokenProvider, Collection<String> scopes)
      throws IOException, GeneralSecurityException {
    return getCredentialFromAccessTokenProvider(accessTokenProvider, scopes);
  }
1351369
def get(cls, scope=None):
        """"""
        if scope is None:
            scope = cls.default
        if isinstance(scope, string_types) and scope in cls._keywords:
            return getattr(cls, scope)
        return scope
562742
function determineClientScope (req, res, next) {
  var params = req.connectParams
  var subject = req.client
  var scope = params.scope || subject.default_client_scope

  if (params.grant_type === 'client_credentials') {
    Scope.determine(scope, subject, function (err, scope, scopes) {
      if (err) { return next(err) }
      req.scope = scope
      req.scopes = scopes
      next()
    })
  } else {
    next()
  }
}
1272228
def get_scope_by_name(self, scope_name):
        
        query_parameters = {}
        if scope_name is not None:
            query_parameters['scopeName'] = self._serialize.query('scope_name', scope_name, 'str')
        response = self._send(http_method='GET',
                              location_id='4e11e2bf-1e79-4eb5-8f34-a6337bd0de38',
                              version='5.0-preview.2',
                              query_parameters=query_parameters)
        return self._deserialize('IdentityScope', response)
1217475
private function retrieveToken($scopes, $cacheKey)
  {
    $this->token = AppIdentityService::getAccessToken($scopes);
    if ($this->token) {
      $this->client->getCache()->set(
          $cacheKey,
          $this->token
      );
    }
  }