common parts of oauth client creation
961020
function createOauthClient(storagePath, clientSecrets) {
  var secrets = fs.readFileSync(path.join(storagePath,  clientSecrets + '.json'));
  if (secrets === undefined) { 
    throw new Error('failed to read secrets file');
  }
  secrets = JSON.parse(secrets);

  var gAuth = new googleAuth();
  var oauthClient = new gAuth.OAuth2(secrets.installed.client_id,
                                     secrets.installed.client_secret,
                                     secrets.installed.redirect_uris[0]);
  return oauthClient;
}
183651
function WPOAuth(options){
  if (!(this instanceof WPOAuth)) return new WPOAuth(options);

  // Options
  this.opts = globals = options || {};
  for (var attr in def){
    this.opts[attr] = this.opts[attr] || def[attr];
  }

  this._code = this.opts.code;

  // Error exceptions
  if (!this.opts.client_id) {
    throw new Error('`client_id` is required');
  }

  if (!this.opts.client_secret) {
    throw new Error('`client_secret` is required');
  }
}
19791
def client
      @client ||= ::OAuth2::Client.new(GoogleAPI.client_id, GoogleAPI.client_secret,
        site: 'https://accounts.google.com',
        token_url: '/o/oauth2/token',
        raise_errors: false
      )
    end
1022686
function createAuthDetails( request ) {
   var auth= { scopedUsers: {} };
   request._connect_auth= auth;
   if( request.session ) {
     request.session.auth= auth;
   }
 }
254770
function create_oauth2_client () {
  var google_client_id = (OPTIONS.GOOGLE_CLIENT_ID) ? OPTIONS.GOOGLE_CLIENT_ID : process.env.GOOGLE_CLIENT_ID;
  var google_client_secret = (OPTIONS.GOOGLE_CLIENT_SECRET) ? OPTIONS.GOOGLE_CLIENT_SECRET : process.env.GOOGLE_CLIENT_SECRET;
  var base_url = (OPTIONS.BASE_URL) ? OPTIONS.BASE_URL : process.env.BASE_URL;
  oauth2_client = new OAuth2Client(
    google_client_id,
    google_client_secret,
    base_url + OPTIONS.REDIRECT_URL
  );
  return oauth2_client;
}
426946
def client
      @client ||= begin
        client = Google::APIClient.new
        client.authorization = Signet::OAuth2::Client.new(
          token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
          audience: 'https://accounts.google.com/o/oauth2/token',
          scope: 'https://www.googleapis.com/auth/analytics.readonly',
          issuer: Gxapi.config.google.email,
          signing_key: self.get_key
        )
        client.authorization.fetch_access_token!
        client
      end
    end
292305
def oauth_query
      {
        client_id:     client_id,
        scope:         scope,
        response_type: "code",
        redirect_uri:  redirect_uri
      }.map do |key, val|
        "#{CGI.escape(key.to_s)}=#{CGI.escape(val.to_s)}"
      end.join(?&)
    end
973979
protected void configureOAuth20Client(final Collection<BaseClient> properties) {
        val index = new AtomicInteger();
        pac4jProperties.getOauth2()
            .stream()
            .filter(oauth -> StringUtils.isNotBlank(oauth.getId()) && StringUtils.isNotBlank(oauth.getSecret()))
            .forEach(oauth -> {
                val client = new GenericOAuth20Client();
                client.setKey(oauth.getId());
                client.setSecret(oauth.getSecret());
                client.setProfileAttrs(oauth.getProfileAttrs());
                client.setProfileNodePath(oauth.getProfilePath());
                client.setProfileUrl(oauth.getProfileUrl());
                client.setProfileVerb(Verb.valueOf(oauth.getProfileVerb().toUpperCase()));
                client.setTokenUrl(oauth.getTokenUrl());
                client.setAuthUrl(oauth.getAuthUrl());
                client.setCustomParams(oauth.getCustomParams());
                val count = index.intValue();
                if (StringUtils.isBlank(oauth.getClientName())) {
                    client.setName(client.getClass().getSimpleName() + count);
                }
                client.setCallbackUrlResolver(new PathParameterCallbackUrlResolver());
                configureClient(client, oauth);

                index.incrementAndGet();
                LOGGER.debug("Created client [{}]", client);
                properties.add(client);
            });
    }
459792
def _create_http_client():
    """"""
    global _http_client

    defaults = {'user_agent': USER_AGENT}
    auth_username, auth_password = _credentials
    if auth_username and auth_password:
        defaults['auth_username'] = auth_username
        defaults['auth_password'] = auth_password

    _http_client = httpclient.AsyncHTTPClient(
        force_instance=True, defaults=defaults,
        max_clients=_max_clients)
512062
def main(client_id, client_secret, scopes):
  """"""
  client_config = ClientConfigBuilder(
      client_type=ClientConfigBuilder.CLIENT_TYPE_WEB, client_id=client_id,
      client_secret=client_secret)

  flow = InstalledAppFlow.from_client_config(
      client_config.Build(), scopes=scopes)
  # Note that from_client_config will not produce a flow with the
  # redirect_uris (if any) set in the client_config. This must be set
  # separately.
  flow.redirect_uri = _REDIRECT_URI

  auth_url, _ = flow.authorization_url(prompt='consent')

  print ('Log into the Google Account you use to access your Ad Manager account'
         'and go to the following URL: \n%s\n' % (auth_url))
  print 'After approving the token enter the verification code (if specified).'
  code = raw_input('Code: ').strip()

  try:
    flow.fetch_token(code=code)
  except InvalidGrantError as ex:
    print 'Authentication has failed: %s' % ex
    sys.exit(1)

  print 'Access token: %s' % flow.credentials.token
  print 'Refresh token: %s' % flow.credentials.refresh_token
880308
function createClient() {
  return Asana.Client.create({
    clientId: clientId,
    clientSecret: clientSecret,
    redirectUri: 'http://localhost:' + port + '/oauth_callback'
  });
}
1283586
def authorization_code(self, request, data, client):
        
        grant = self.get_authorization_code_grant(request, request.POST,
                client)
        if constants.SINGLE_ACCESS_TOKEN:
            at = self.get_access_token(request, grant.user, grant.scope, client)
        else:
            at = self.create_access_token(request, grant.user, grant.scope, client)
            rt = self.create_refresh_token(request, grant.user, grant.scope, at,
                    client)

        self.invalidate_grant(grant)

        return self.access_token_response(at)
956844
def create_client(access_token):
    """"""
    url = 'http://keycloak:8080/auth/admin/realms/dci-test/clients'
    r = requests.post(url,
                      data=json.dumps(client_data),
                      headers=get_auth_headers(access_token))
    if r.status_code in (201, 409):
        print('Keycloak client dci created successfully.')
    else:
        raise Exception(
            'Error while creating Keycloak client dci:\nstatus code %s\n'
            'error: %s' % (r.status_code, r.content)
        )
54393
function(){
    // Initialize the API object
    if (this.mainView) {
      this.mainView.clear();
    }
    var url = this.options.url;
    if (url && url.indexOf('http') !== 0) {
      url = this.buildUrl(window.location.href.toString(), url);
    }
    if(this.api) {
      this.options.authorizations = this.api.clientAuthorizations.authz;
    }
    this.options.url = url;
    this.headerView.update(url);

    this.api = new SwaggerClient(this.options);
  }
835599
function temporaryCredentials (done) {
  var strategy = this
  var provider = strategy.provider
  var endpoint = strategy.endpoints.credentials
  var client = strategy.client
  var method = endpoint.method && endpoint.method.toLowerCase()
  var url = endpoint.url
  var header = endpoint.header || 'Authorization'
  var scheme = endpoint.scheme || 'OAuth'
  var accept = endpoint.accept || 'application/x-www-form-urlencoded'
  var key = client.oauth_consumer_key
  var secret = client.oauth_consumer_secret
  var signer = provider.oauth_signature_method || 'PLAINTEXT'
  var realm = provider.realm
  var callback = provider.oauth_callback
  var params = {}

  // Initialize request
  var req = request[method || 'post'](url)

  // Build request parameters
  params.oauth_consumer_key = key
  params.oauth_signature_method = signer
  params.oauth_timestamp = timestamp()
  params.oauth_nonce = nonce(32)
  params.oauth_callback = callback
  params.oauth_version = '1.0'

  // Generate signature (is next line needed for PLAINTEXT?)
  var input = signatureBaseString(method, url, normalizeParameters(params))
  params.oauth_signature = sign(signer, input, secret)

  if (realm) { params.realm = realm }

  // Set Authorization header
  req.set(header, scheme + ' ' + authorizationHeaderParams(params))

  // Set other headers
  req.set('Accept', accept)
  req.set('User-Agent', agent)

  // Execute request
  return req.end(function (err, res) {
    if (err) { return done(err) }
    var response = qs.parse(res.text)

    if (res.statusCode !== 200) {
      return done(new Error(res.text))
    }

    done(null, response)
  })
}
1152272
def authenticate_with_sso(attributes)
      response = @oauth_connection.post do |req|
        req.url '/oauth/token', :grant_type => 'sso', :client_id => api_key, :client_secret => api_secret
        req.body = attributes
      end

      @oauth_token = OAuthToken.new(response.body)
      configure_oauth
      [@oauth_token, response.body['new_user_created']]
    end
1346033
protected function makeMainClient()
	{
		$this->mainClientData['uses'] = [
			'GuzzleHttp\Client as GuzzleClient'
		];
		$this->mainClientData['managers'] = [];
		$this->mainClientData['className'] = 'ApiClient';
		$this->mainClientData['classPhpDocTitle'] = $this->openApiFileContent['info']['title'] . ' client class';
		$this->mainClientData['classPhpDocTitle'] .= $this->openApiFileContent['info']['version'] ? (' (version ' . $this->openApiFileContent['info']['version'] . ')') : '';
		$this->mainClientData['namespace'] = $this->namespace;

		$this->mainClientData['info'] = $this->openApiFileContent['info'];

		$firstKey = array_keys($this->openApiFileContent['servers'])[0];
		$this->mainClientData['apiBaseUrl'] = $this->openApiFileContent['servers'][$firstKey]['url'];

		// Security
		// @todo Not only OAuth support
		// @todo Scopes support ?
		$this->mainClientData['useBearerToken'] = false;
		if (isset($this->openApiFileContent['security'])) {
			foreach ($this->openApiFileContent['security'] as $s) {
				foreach ($s as $securityRequirement => $scope) {
					// Ignoring scopes...
					if (!isset($this->mainClientData['security'])) {
						$this->mainClientData['security'] = [];
					}
					$this->mainClientData['security'][$securityRequirement] = $this->openApiFileContent['components']['securitySchemes'][$securityRequirement];

					if ($this->openApiFileContent['components']['securitySchemes'][$securityRequirement]['type'] == 'http') {
						if ($this->openApiFileContent['components']['securitySchemes'][$securityRequirement]['scheme'] == 'bearer') {
							$this->mainClientData['useBearerToken'] = true;
						}
					}

					if ($this->openApiFileContent['components']['securitySchemes'][$securityRequirement]['type'] == 'oauth2') {
						$this->mainClientData['useBearerToken'] = true;
					}
				}
			}
		}

		// Add extra Guzzle classes in uses
		if ($this->mainClientData['useBearerToken']) {
			$this->mainClientData['uses'][] = 'Psr\Http\Message\RequestInterface';
			$this->mainClientData['uses'][] = 'GuzzleHttp\HandlerStack';
			$this->mainClientData['uses'][] = 'GuzzleHttp\Handler\CurlHandler';
			$this->mainClientData['uses'][] = 'GuzzleHttp\Middleware';
		}

		foreach ($this->managersData as $managerName => $managerData) {
			$this->mainClientData['uses'][] = $this->namespace . '\\Managers\\' . $managerName . 'Manager';
			$this->mainClientData['managers'][$managerName] = [
				'name' => $managerName,
				'className' => $managerName . 'Manager',
				'lowerCamelCaseClassName' => lcfirst($managerName . 'Manager')
			];
		}
	}