/*
Set the "Authorization" HTTP header into the headers object from the given
auth info.
- Bearer auth if `token`.
- Else, Basic auth if `username`.
- Else, if the authorization key exists, then it is removed from headers.
333768
function _setAuthHeaderFromAuthInfo(headers, authInfo) {
    if (authInfo.token) {
        headers.authorization = 'Bearer ' + authInfo.token;
    } else if (authInfo.username) {
        headers.authorization = _basicAuthHeader(authInfo.username,
            authInfo.password);
    } else if (headers.authorization) {
        delete headers.authorization;
    }
}
326782
@Override
    public boolean authorizeURLRequest(Request.Builder builder) {
        loadTokens();
        if (IDToken != null && !haveSessionCookie) {
            String auth = String.format(Locale.ENGLISH, "Bearer ", IDToken);
            builder.addHeader("Authorization", auth);
            return true;
        } else {
            return false;
        }
    }
73144
protected function setAuthenticationHeader($response, $token = null)
    {
        $token = $token ?: $this->auth->refresh();
        $response->headers->set('Authorization', 'Bearer '.$token);

        return $response;
    }
810573
public function setAuth($username, $password, $auth_type = null)
    {
        if (is_null($auth_type)) {
            $auth_type = CURLAUTH_BASIC;
        }

        $this->curl_opts[CURLOPT_HTTPAUTH] = $auth_type;
        $this->curl_opts[CURLOPT_USERPWD] = "{$username}:{$password}";
    }
240160
public function header($key, $value=null,$http_response_code=null) {
        if($value) {
            $key = $key.':'.$value;
        }
        headers_sent() or header($key,true,$http_response_code);
    }
693682
def set_response_headers(self, response: HttpResponse) -> HttpResponse:
        
        public_name = os.environ.get('SERVER_PUBLIC_NAME')
        response_headers = {
            'access-control-allow-headers': self.app.allowed_headers,
            'access-control-allow-methods': self.app.allowed_methods,
            'access-control-allow-origin': self.app.allowed_origins,
            'access-control-allow-credentials': True,
            'www-authenticate': "Bearer",
            'server-public-name': public_name if public_name else "No one",
            'user-info': "Rinzler Framework rulez!"
        }

        response_headers.update(self.app.default_headers)

        for key in response_headers:
            response[key] = response_headers[key]

        status = response.status_code
        if status != 404:
            self.app.log.info("< {0}".format(status))

        return response
712274
function getTokenFromHeader(request) {
  if (!request.headers || !request.headers.has('authorization')) {
    throw new UnauthorizedError('No authorization header present');
  }

  const parts = request.headers.get('authorization').split(" ");

  if (parts.length === 2) {
    const scheme = parts[0];
    const credentials = parts[1];

    if (/^Bearer$/i.test(scheme)) {
      return credentials;
    } else {
      throw new UnauthorizedError('Bad Authorization header format. Format is "Authorization: Bearer token"');
    }
  } else {
    throw new UnauthorizedError('Bad Authorization header format. Format is "Authorization: Bearer token"');
  }
}
986529
private String getAuthHeader(HttpServletRequest request, String authType)
      throws HttpAuthenticationException {
    String authHeader = request.getHeader(HttpAuthUtils.AUTHORIZATION);
    // Each http request must have an Authorization header
    if (authHeader == null || authHeader.isEmpty()) {
      throw new HttpAuthenticationException("Authorization header received " +
          "from the client is empty.");
    }

    String authHeaderBase64String;
    int beginIndex;
    if (isKerberosAuthMode(authType)) {
      beginIndex = (HttpAuthUtils.NEGOTIATE + " ").length();
    }
    else {
      beginIndex = (HttpAuthUtils.BASIC + " ").length();
    }
    authHeaderBase64String = authHeader.substring(beginIndex);
    // Authorization header must have a payload
    if (authHeaderBase64String == null || authHeaderBase64String.isEmpty()) {
      throw new HttpAuthenticationException("Authorization header received " +
          "from the client does not contain any data.");
    }
    return authHeaderBase64String;
  }
140168
func (t *StaticToken) SetAuthHeader(r *http.Request) {
	typ := t.Type
	if typ == "" {
		typ = "Bearer"
	}
	r.Header.Set("Authorization", typ+" "+t.Value)
}
1136409
function swaggerSecurity(context, headers) {
    var security = null;
    headers.filter(function(header) {
        return header.name.toLowerCase() === 'authorization';
    }).forEach(function(header) {
        if (header.value.match(/^Basic /)) {
            if (!security) security = {};
            security['basic'] = [];
            context.swagger.securityDefinitions['basic'] = { type: 'basic' };
        } else if (header.value.match(/^Bearer /)) {
            if (!security) security = {};
            if (context.options.bearerAsApikey) {
                security['bearer'] = [];
                context.swagger.securityDefinitions['bearer'] = {
                    type: 'apiKey', in: 'header', name: 'Authorization'
                };
            } else {
                security['oauth2'] = [];
                context.swagger.securityDefinitions['oauth2'] = {
                    type: 'oauth2', flow: 'accessCode',
                    authorizationUrl: '', tokenUrl: '', scopes: {} };
            }
        }
    });
    return security;
}
963865
protected void addBasicAuthHeader(HttpHeaders headers, String key){
		headers.add(HEADER_AUTHORIZATION, buildBasicAuthValue(key));
	}
813616
private Map<String, String> getHttpHeaderBasic() throws Exception {
        
        return new HashMap<String, String>(){{
            put("Authorization", "Basic " + getHttpHeaderBasicKey());
        }};
    }
1368090
public function setOAuth2Token ($token)
    {
        if (!StringUtilities::isNullOrEmpty($token))
        {
            $this->oAuth2Token = $token;
            $this->headers[]   = "Authorization: OAuth " . $this->oAuth2Token;
        }
    }
190511
function setAcceptHeader(req) {
    var httpRequest = req.httpRequest;
    if (!httpRequest.headers.Accept) {
      httpRequest.headers['Accept'] = 'application/json';
    }
  }
825014
function parseHeader(authHeader, callback){
        try {
            var parts=authHeader.split(/:/),
                username=parts[0],
                password=parts[1];

            callback(null, {username: username, password: password});
        }
        catch(ex){
            callback(ex);
        }
    }
1155456
public void setRequestHeader(String header, String value) {
        LOG.entering(CLASS_NAME, "setRequestHeader", new Object[] {header, value});
        HttpRequestUtil.validateHeader(header);
        connection.addRequestProperty(header, value);
    }
523265
public void setAuthorization(TopicAuthorization authorization)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        SibTr.entry(tc, "setAuthorization","authorization: "+authorization);

    this.authorization = authorization;

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "setAuthorization");
  }