Synchronous OAuth 2.0 Bearer client
543928
def sync_client(self):
        """"""
        if not self._sync_client:
            self._sync_client = AlfSyncClient(
                token_endpoint=self.config.get('OAUTH_TOKEN_ENDPOINT'),
                client_id=self.config.get('OAUTH_CLIENT_ID'),
                client_secret=self.config.get('OAUTH_CLIENT_SECRET')
            )
        return self._sync_client
705943
function createOAuthWrapper(oauthkey,
	oauthsecret, headers) {

	return new OAuthClient(
				'https://api.7digital.com/1.2/oauth/requesttoken',
				accessTokenUrl,
				oauthkey, oauthsecret, '1.0', null, 'HMAC-SHA1', 32, headers);
}
529195
def _get_oauth_token(self):
        
        url = urljoin(self.api_url, '/oauth2/token')

        oauth = OAuth2Session(
            client_id=self._client_id,
            redirect_uri=config.REDIRECT_URI,
        )

        token = oauth.fetch_token(
            token_url=url,
            code=self._auth_code,
            client_secret=self._client_secret,
        )

        return token
212501
def client_ready(self):
        
        if not self.auth_complete():
            return False
        if not self._client_ready():
            self._connection.work()
            return False
        return True
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;
}
50476
function (req, res, next) {
            if (options.forceAuthorize) {
                return next();
            }
            var userId = req.oauth2.user.id;
            var clientId = req.oauth2.client.id;
            var scope = req.oauth2.req.scope;
            models.Permissions.isAuthorized(clientId, userId, scope,
                function (err, authorized) {
                    if (err) {
                        return next(err);
                    } else if (authorized) {
                        req.oauth2.res = {};
                        req.oauth2.res.allow = true;
                        server._respond(req.oauth2, res, function (err) {
                            if (err) {
                                return next(err);
                            }
                            return next(new AuthorizationError('Unsupported response type: '
                                + req.oauth2.req.type, 'unsupported_response_type'));
                        });
                    } else {
                        next();
                    }
                });
        }
764173
function(handler) {
        if (typeof accessToken == 'undefined') {
            var body = {
                client_id: clientId,
                client_secret: clientSecret,
                username: username,
                password: password,
                grant_type: 'password'
            };

            if (thisObject.debug) {
                console.log("Making oAuth call...");
            }

            var options =  {
                url: 'https://app1pub.smappee.net/dev/v1/oauth2/token',
                headers: {
                    'Host': 'app1pub.smappee.net'
                },
                form: body
            };

            request.post(options, function (err, httpResponse, body) {
                if (err) {
                    return console.error('Request failed:', err);
                }
                if (thisObject.debug) {
                    console.log('Server responded with:', body);
                }

                accessToken = JSON.parse(body);
                handler(accessToken);
            });
        } else {
            handler(accessToken)
        }
    }
329357
def _get_auth_token(self):
        
        url = '/%s/oauth2/token' % getattr(
            settings, 'RESTCLIENTS_O365_TENANT', 'test')
        headers = {'Accept': 'application/json'}
        data = {
            "grant_type": "client_credentials",
            "client_id": getattr(settings,
                                 'RESTCLIENTS_O365_CLIENT_ID',
                                 None),
            "client_secret": getattr(settings,
                                     'RESTCLIENTS_O365_CLIENT_SECRET',
                                     None),
            "resource": self._api_host
        }
        body = urlencode(data)
        auth_pool = self._get_pool(self._auth_host)
        response = get_live_url(auth_pool, 'POST', self._auth_host,
                                url, headers=headers, body=body,
                                service_name='o365')
        try:
            json_data = json.loads(response.data)
            if response.status == 200:
                return "%s %s" % (
                    json_data['token_type'], json_data['access_token'])
            else:
                raise DataFailureException(
                    url, response.status,
                    'Auth token failure: %s - %s' % (
                        json_data.get('error', 'unknown'),
                        json_data.get('error_description', 'no description')))
        except ValueError:
            raise DataFailureException(
                url, response.status,
                'Auth token failure: %s' % (response.data))
908234
private String getOAuth2Header(OAuth2Compatible oAuth2Compatible) throws OAuthException {
    if (adsLibConfiguration.isAutoRefreshOAuth2TokenEnabled()) {
      try {
        oAuth2Helper.refreshCredential(oAuth2Compatible.getOAuth2Credential());
      } catch (IOException e) {
        throw new OAuthException("OAuth2 token could not be refreshed.", e);
      }
    }

    return oAuth2AuthorizationHeaderProvider.getOAuth2AuthorizationHeader(oAuth2Compatible);
  }
1665
def set_oauth_client(self, consumer_key, consumer_secret):
        
        self.oauth_client = oauth1.Client(consumer_key, consumer_secret)
269684
function (req, res, next) {
      if (req.query.return) {
        req.session.oauth2return = req.query.return;
      }
      next();
    }
1188171
def _get_oauth_session(self):
        

        return self._get_session(
            OAuth2Session(
                client_id=self.client_id,
                token=self.token,
                token_updater=self.token_updater,
                auto_refresh_url=self.token_url,
                auto_refresh_kwargs={
                    "client_id": self.client_id,
                    "client_secret": self.client_secret
                }
            )
        )
62946
private OkHttpClient createOkHttpClient(OkHttpAuthenticator authenticator, int logLevel) {

        OkHttpClient.Builder builder = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor(logLevel))
                .connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
                .writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)
                .readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
                .authenticator(authenticator);

        return builder.build();
    }
544057
def request_access(self, verifier):
        
        client = OAuth1(
            client_key=self._server_cache[self.client.server].key,
            client_secret=self._server_cache[self.client.server].secret,
            resource_owner_key=self.store["oauth-request-token"],
            resource_owner_secret=self.store["oauth-request-secret"],
            verifier=verifier,
        )

        request = {"auth": client}
        response = self._requester(
            requests.post,
            "oauth/access_token",
            **request
        )

        data = parse.parse_qs(response.text)

        self.store["oauth-access-token"] = data[self.PARAM_TOKEN][0]
        self.store["oauth-access-secret"] = data[self.PARAM_TOKEN_SECRET][0]
        self._server_tokens = {}
794341
function createGlobalManagerService($http, authService) {
  //Init the sync service
  syncNetworkInit.initSync($http).catch(function(error) {
    logger.getLogger().error("Failed to initialize sync", error);
  });
  var syncManager = new SyncManager();
  authService.setLoginListener(function(profileData) {
    syncManager.syncManagerMap(profileData);
  });

  authService.setLogoutListener(function() {
    syncManager.removeManagers();
  });
  return syncManager;
}
735452
function OAuth2Error(message, code, uri, status) {
  Error.call(this);
  this.message = message;
  this.code = code || 'server_error';
  this.uri = uri;
  this.status = status || 500;
}
600839
@Override
  public void onConnect(URI serverHost) throws IOException {
    if (!StringUtils.isEmpty(accessToken)) {
      return; //No need to be called if accessToken is active.
    }

    try {
      getLog().info("Getting Oauth2 access token.");
      OAuthClientRequest request = OAuthClientRequest.tokenLocation(serverHost.toString())
          .setGrantType(GrantType.PASSWORD)
          .setClientId(clientId)
          .setClientSecret(clientSecret)
          .setUsername(userId)
          .setPassword(password + securityToken).buildQueryMessage();
      OAuthClient client = new OAuthClient(new URLConnectionClient());
      OAuthJSONAccessTokenResponse response = client.accessToken(request, OAuth.HttpMethod.POST);

      accessToken = response.getAccessToken();
      setCurServerHost(new URI(response.getParam("instance_url")));
    } catch (OAuthProblemException e) {
      throw new NonTransientException("Error while authenticating with Oauth2", e);
    } catch (OAuthSystemException e) {
      throw new RuntimeException("Failed getting access token", e);
    } catch (URISyntaxException e) {
      throw new RuntimeException("Failed due to invalid instance url", e);
    }
  }