Refresh Monzo OAuth 2 token.

        Official docs:
            https://monzo.com/docs/#refreshing-access

        :raises UnableToRefreshTokenException: when token couldn't be refreshed
170022
def _refresh_oath_token(self):
        
        url = urljoin(self.api_url, '/oauth2/token')
        data = {
            'grant_type': 'refresh_token',
            'client_id': self._client_id,
            'client_secret': self._client_secret,
            'refresh_token': self._token['refresh_token'],
        }

        token_response = requests.post(url, data=data)
        token = token_response.json()

        # Not ideal, but that's how Monzo API returns errors
        if 'error' in token:
            raise CantRefreshTokenError(
                "Unable to refresh the token: {}".format(token)
            )

        self._token = token
        self._save_token_on_disk()
989184
def refresh(self, access_token=None, **kwargs):
        
        if not self.token_lock.locked():
            with self.token_lock:
                if access_token == self.access_token or access_token is None:
                    if self.developer_token is not None:
                        r = self._httpclient.request(
                            method='POST',
                            url=self.developer_token_url,
                            path='/request_token',
                            headers={
                                'Authorization': 'Bearer {}'.format(
                                    self.developer_token
                                )
                            },
                            timeout=30,
                            raise_for_status=True
                        )

                    elif all(
                        [
                            self.client_id,
                            self.client_secret,
                            self.refresh_token
                        ]
                    ):
                        data = {
                            'client_id': self.client_id,
                            'client_secret': self.client_secret,
                            'refresh_token': self.refresh_token,
                            'grant_type': 'refresh_token'
                        }
                        r = self._httpclient.request(
                            method='POST',
                            url=self.token_url,
                            json=data,
                            path='/api/oauth2/RequestToken',
                            **kwargs
                        )
                    else:
                        raise PartialCredentialsError(
                            "Missing one or more required credentials"
                        )

                    if r:
                        if not r.ok:
                            raise PanCloudError(
                                '%s %s: %s' % (
                                r.status_code, r.reason, r.text)
                            )
                        try:
                            r_json = r.json()
                        except ValueError as e:
                            raise PanCloudError("Invalid JSON: %s" % e)
                        else:
                            if r.json().get(
                                'error_description'
                            ) or r.json().get(
                                'error'
                            ):
                                raise PanCloudError(r.text)
                            self.access_token = r_json.get(
                                'access_token', None
                            )
                            self.jwt_exp = self._decode_exp(
                                self.access_token_)
                            if r_json.get('refresh_token', None):
                                self.refresh_token = \
                                    r_json.get('refresh_token')
                            self.write_credentials()
                        return self.access_token_
227705
def refresh_access_token(self, refresh_token, redirect_uri=None):
        '''
        
        '''
        redirect = redirect_uri or self._redirect_uri
        resp_text = _http('POST', 'https://graph.qq.com/oauth2.0/token',
                          refresh_token=refresh_token,
                          client_id=self._client_id, client_secret=self._client_secret,
                          redirect_uri=redirect, grant_type='refresh_token')
        return self._parse_access_token(resp_text)
719295
def refresh_token(self, refresh_token):
        

        response = requests.post('%saccess_token' % OAUTH_URL, {
                                 'refresh_token': refresh_token,
                                 'grant_type': 'refresh_token',
                                 'client_id': self.client_id,
                                 'client_secret': self.client_secret
                                 })
        resp = json.loads(response.content)

        if 'access_token' in resp:
            self.token = resp['access_token']

        return resp
40889
private synchronized boolean refreshAuthToken(final AuthHandler handler,
                                                  final boolean forceRefresh) {

        if (handler == null) {
            return false;
        }

        AuthToken token = authToken.get();

        if (!forceRefresh && token != null && token.isValid()) {
            logger.fine("Auth token is already valid");
            return true;
        }

        try {
            handler.setForceRefresh(forceRefresh);
            token = handler.call();
            authToken.set(token);

            if (token != null) {
                if (token instanceof UserBearerAuthToken) {
                    final UserBearerAuthToken bt = (UserBearerAuthToken) token;
                    logger.info("Acquired auth token. Expires: "
                                + bt.getExpires() + " token="
                                + bt.getToken());
                } else if (token instanceof ProjectBearerAuthToken) {
                    ProjectBearerAuthToken pt = (ProjectBearerAuthToken) token;
                    logger.info("Acquired proj token. Expires: " + pt.getExpires() + " token="
                                + pt.getToken());
                } else {
                    logger.info("Acquired auth token. Token valid="
                                + token.isValid());
                }
            }
        } catch (ExecutionException e) {
            final Throwable cause = e.getCause();

            if (cause != null) {
                logger.warning("Authentication failed: " + cause.getMessage());
            } else {
                logger.warning("Authentication failed: " + e.getMessage());
            }
        } catch (Exception e) {
            logger.warning("Authentication failed: " + e.getMessage());
        } finally {
            handler.setForceRefresh(false);
        }
        return true;
    }
529562
def refresh(params = {}, access_token_opts = {}, access_token_class = self.class)
      raise('A refresh_token is not available') unless refresh_token
      params[:grant_type] = 'refresh_token'
      params[:refresh_token] = refresh_token
      new_token = @client.get_token(params, access_token_opts, access_token_class)
      new_token.options = options
      new_token.refresh_token = refresh_token unless new_token.refresh_token
      new_token
    end
115364
def _refresh_token_flow(self):
        """"""
        url = '%s%s/oauth2/token' % (self.scheme, self.host)
        options = {
            'grant_type': 'refresh_token',
            'client_id': self.options.get('client_id'),
            'client_secret': self.options.get('client_secret'),
            'refresh_token': self.options.get('refresh_token')
        }
        options.update({
            'verify_ssl': self.options.get('verify_ssl', True),
            'proxies': self.options.get('proxies', None)
        })
        self.token = wrapped_resource(
            make_request('post', url, options))
        self.access_token = self.token.access_token
404602
def refresh_token(self, arguments):
        

        new_access_token = None

        auth = ExistAuth(self.client_id, self.client_secret)
        resp = auth.refresh_token(self.access_token)
        if auth.token:
            new_access_token = auth.token['access_token']
            print('OAuth token refreshed: %s' % new_access_token)
            self.write_config(new_access_token)
        else:
            print('ERROR: We were unable to refresh the OAuth token | %s' % json.dumps(resp))
514523
def get_access_token(self, refresh_token):
        

        token = requests.post(GOOGLE_OAUTH2_TOKEN_URL, data=dict(
            refresh_token=refresh_token,
            grant_type='refresh_token',
            client_id=self.client_id,
            client_secret=self.client_secret,
        )).json()

        if not token or token.get('error'):
            return

        return token
887290
def _request_token(self, force=False):
        
        if self.login_data is None:
            raise RuntimeError("Don't have a token to refresh")

        if not force:
            if not self._requires_refresh_token():
                # no need to refresh as token is valid
                return True

        headers = {
            "Accept": "application/json",
            'Authorization':
                'Bearer ' + self.login_data['token']['accessToken']
        }

        url = self.api_base_url + "account/RefreshToken"

        response = requests.get(url, headers=headers, timeout=10)

        if response.status_code != 200:
            return False

        refresh_data = response.json()

        if 'token' not in refresh_data:
            return False

        self.login_data['token']['accessToken'] = refresh_data['accessToken']
        self.login_data['token']['issuedOn'] = refresh_data['issuedOn']
        self.login_data['token']['expiresOn'] = refresh_data['expiresOn']

        return True
1025026
public function getOauthRefreshToken($refresh_token){
        $result = $this->http_get(self::API_BASE_URL_PREFIX.self::OAUTH_REFRESH_URL.'appid='.$this->appid.'&grant_type=refresh_token&refresh_token='.$refresh_token);
        if ($result)
        {
            $json = json_decode($result,true);
            if (!$json || !empty($json['errcode'])) {
                $this->errCode = $json['errcode'];
                $this->errMsg = $json['errmsg'];
                return false;
            }
            $this->user_token = $json['access_token'];
            return $json;
        }
        return false;
    }
395435
def refresh(self):
        """"""
        if self.refresh_token is None:
            raise InvalidInvocation("refresh token not provided")
        self._request_token(
            grant_type="refresh_token", refresh_token=self.refresh_token
        )
732094
public function refreshAccessToken(OAuthToken $token)
    {
        $params = [
            'grant_type' => 'refresh_token'
        ];
        $params = array_merge($token->getParams(), $params);

        $request = $this->createRequest()
            ->setMethod('POST')
            ->setUrl($this->refreshTokenUrl)
            ->setData($params);

        $this->applyClientCredentialsToRequest($request);

        $response = $this->sendRequest($request);

        $token = $this->createToken(['params' => $response]);
        $this->setAccessToken($token);

        return $token;
    }
565342
public synchronized void refreshWithToken(String clientToken, String accessToken) throws AuthenticationException {
		authResult = authenticationService.refresh(Objects.requireNonNull(clientToken), Objects.requireNonNull(accessToken));
	}
681205
protected function refreshToken()
    {
        $token = $this->authorization->getApi()
                                     ->getAuthorizerToken(
                                         $this->authorization->getAuthorizerCorpId(),
                                         $this->authorization->getAuthorizerPermanentCode()
                                     );

        $this->authorization->setAuthorizerAccessToken($token['access_token'], $token['expires_in'] - 1500);

        return $token['access_token'];
    }
982543
AuthenticationResult acquireAccessTokenFromRefreshToken(String resource, String refreshToken, boolean isMultipleResourceRefreshToken) throws IOException {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        try {
            return refreshTokenClient.refreshToken(domain(), clientId(), resource, refreshToken, isMultipleResourceRefreshToken);
        } catch (Exception e) {
            return null;
        } finally {
            executor.shutdown();
        }
    }
85889
def refresh(self, scope_list=None):
        
        request_data = self.get_refresh_token_params(scope_list)
        res = self._session.post(**request_data)
        if res.status_code != 200:
            raise APIException(
                request_data['url'],
                res.status_code,
                response=res.content,
                request_param=request_data,
                response_header=res.headers
            )
        json_res = res.json()
        self.update_token(json_res)
        return json_res