retrieve token from provider. Ensures each thread checks the token is
null prior to making the callout to IAM
176048
protected synchronized void retrieveToken() {

		log.debug("OAuthTokenManager.retrieveToken");

		if (token == null || (Long.valueOf(token.getExpiration()) < System.currentTimeMillis() / 1000L)) {

			log.debug("Token is null, retrieving initial token from provider");
			boolean tokenRequest = true;
			int retryCount = 0;

			while (tokenRequest && retryCount < this.iamMaxRetry) {
				try {
					++retryCount;
					token = provider.retrieveToken();
					tokenRequest = false;
				} catch (OAuthServiceException exception) {
					log.debug("Exception retrieving IAM token. Returned status code " + exception.getStatusCode()
							+ "Retry attempt " + retryCount);
					tokenRequest = shouldRetry(exception.getStatusCode()) ? true : false;
					if (!tokenRequest || retryCount == this.iamMaxRetry)
						throw exception;
				}
			}

			if(null == token) throw new OAuthServiceException("Null token returned by the Token Provider");

			cacheToken(token);
		}
	}
848551
private String getToken() {

        SessionData session = dataMgr.getSessionDAO().session();
        if (session != null && session.getExpiresOn() > System.currentTimeMillis()) {
            return session.getAccessToken();
        }

        return null;
    }
599267
def obtain_token(self):
        
        token_end_points = ('token/obtain',
                            'obtain-token',
                            'obtain_token')
        for end_point in token_end_points:
            try:
                return self.auth[end_point]._(page_size=None)['token']
            except BeanBagException as e:
                if e.response.status_code != 404:
                    raise
        raise Exception('Could not obtain token from any known URL.')
460340
@Override
	public String getToken() {

		log.debug("DefaultTokenManager getToken()");

		if (!checkCache()) {
			retrieveToken();
		}

		// retrieve from cache
		if (token == null) {
			token = retrieveTokenFromCache();
		}

		// check if expired
		if (hasTokenExpired(token)) {
			token = retrieveTokenFromCache();
		}

		// check if token should be refreshed. If a refreshtoken is not present, the token manager will call upon the original tokenprovider retrieve a fresh token
		if (isTokenExpiring(token) && !isAsyncInProgress()) {
			if (null != token.getRefresh_token()) {
				this.asyncInProgress = true;
				submitRefreshTask();
			} else {
				retrieveToken();
				token = retrieveTokenFromCache();
			}
		}

		if (token.getAccess_token() != null && !token.getAccess_token().isEmpty()) {
			return token.getAccess_token();
		} else if (token.getDelegated_refresh_token()!= null && !token.getDelegated_refresh_token().isEmpty()) {
			return token.getDelegated_refresh_token();
		} else if (token.getIms_token() != null && !token.getIms_token().isEmpty()) {
			return token.getIms_token();
		} else {
			return token.getUaa_token();
		}

	}
519749
public String getToken(){
		if(this.tokenPosition>0){
			String[] ar = StringUtils.split(this.line, null, this.tokenPosition+1);
			if(ar!=null && ar.length>(this.tokenPosition-1)){
				return StringUtils.trim(ar[this.tokenPosition-1]);
			}
		}
		return null;
	}
35980
def get_client(provider, token=''):
    ""
    cls = OAuth2Client
    if provider.request_token_url:
        cls = OAuthClient
    return cls(provider, token)
895435
final Token currentToken() throws IllegalStateException, NoSuchElementException {
        if (currentToken == null) {
            if (completed) {
                throw new NoSuchElementException(CommonI18n.noMoreContent.text());
            }
            throw new IllegalStateException(CommonI18n.startMethodMustBeCalledBeforeConsumingOrMatching.text());
        }
        assert currentToken != null;
        return currentToken;
    }
547205
def get_provider_token(self, provider_secret):
        
        return self._post(
            'service/get_provider_token',
            data={
                'corpid': self._client.corp_id,
                'provider_secret': provider_secret,
            }
        )
1087149
static TokenLifeCycleManager getInstance(final String iamEndpoint,
            final String apiKey) {
        if (iamEndpoint == null || iamEndpoint.isEmpty()) {
            throw new IllegalArgumentException(
                    "Cannot initialize with null or empty IAM endpoint.");
        }
        if (apiKey == null || apiKey.isEmpty()) {
            throw new IllegalArgumentException(
                    "Cannot initialize with null or empty IAM apiKey.");
        }
        return getInstanceUnchecked(iamEndpoint, apiKey);
    }
378470
private Claims getClaimsFromToken(String token) {
        Claims claims;
        try {
            claims = Jwts.parser()
                    .setSigningKey(jwtProperties.getSecret())
                    .parseClaimsJws(token)
                    .getBody();
        } catch (Exception e) {
            log.error("get claims from jwt token error : {}", e.getMessage());
            claims = null;
        }
        return claims;
    }
1235911
def _get_tokens(self, authn_response, context):
        
        if "code" in authn_response:
            # make token request
            args = {
                "code": authn_response["code"],
                "redirect_uri": self.client.registration_response['redirect_uris'][0],
            }

            token_resp = self.client.do_access_token_request(scope="openid", state=authn_response["state"],
                                                             request_args=args,
                                                             authn_method=self.client.registration_response[
                                                                 "token_endpoint_auth_method"])

            self._check_error_response(token_resp, context)
            return token_resp["access_token"], token_resp["id_token"]

        return authn_response.get("access_token"), authn_response.get("id_token")
18447
SourcedToken getEquivalentToken(Token tok) {
        if (unsourcedTokens.contains(tok.getValue())) {
            for (int i=0; i<tokens.length; i++) {
                if (tokens[i].getValue().equals(tok.getValue())) {
                    return tokens[i];
                }
            }
            System.out.println("This is a problem");
            return null;
        } else {
            return null;
        }
    }
874748
function getToken (token, callback) {

    if (token != null &&
        token != '') {

        // Fetch token from database or cache

        if (token == 'h328hdkasjd3') {

            var record = { algorithm: 'hmac-sha-256',   // Required
                secret: '23hdkdho2893hdkjd',            // Required
                userId: 'johndoe'                       // Application-specific field
            };

            callback(record);
        }
        else {

            // Token not found

            callback({});
        }
    }
    else {

        // Invalid token request

        callback({});
    }
}
239780
public String getIdFromToken(String token) {
        try {
            final Claims claims = getClaimsFromToken(token);
            return (String) claims.get(CLAIM_KEY_ID);
        } catch (Exception e) {
            log.error("get id from jwt token error : {}", e.getMessage());
            return null;
        }
    }
784076
def get_token(self):
        """"""
        auth_resp = self.get_auth()

        if auth_resp['status'] == 'mfa_req':
            token_resp = self.get_mfa(auth_resp)
        else:
            token_resp = auth_resp

        token = token_resp['data']['client_token']['client_token']
        return token
892001
private function getSecurityToken()
    {
        if ($this->container->get('security.context')->getToken() instanceof TokenInterface) {
            return $this->container->get('security.context')->getToken();
        }

        return null;
    }
300503
def provider(self, service_provider, **kwargs):
        
        getattr(service_provider, '__init__')(kwargs.get('token'))
        return getattr(service_provider, 'read_data')(**kwargs)