<commit_before>package oauth2

import (
	"errors"
	"net/http"
	"strings"
)

// NewBearerTokenResponse creates and returns a new token response that carries
// a bearer token.
func NewBearerTokenResponse(token string, expiresIn int) *TokenResponse {
	return NewTokenResponse("bearer", token, expiresIn)
}

// ParseBearerToken parses and returns the bearer token from a request. It will
// return standard errors if the extraction failed.
//
// Note: The spec also allows obtaining the bearer token from query parameters
// and the request body (form data). This implementation only supports obtaining
// the token from the "Authorization" header as this is the most common use case
// and considered most secure.
func ParseBearerToken(r *http.Request) (string, error) {
	// read header
	h := r.Header.Get("Authorization")

	// split header
	s := strings.SplitN(h, " ", 2)
	if len(s) != 2 || !strings.EqualFold(s[0], "bearer") {
		return "", errors.New("Malformed or missing authorization header")
	}<commit_msg>added bearer token type constant<commit_after>package oauth2

import (
	"errors"
	"net/http"
	"strings"
)

// The bearer token type.
const BearerTokenType = "bearer"

// NewBearerTokenResponse creates and returns a new token response that carries
// a bearer token.
func NewBearerTokenResponse(token string, expiresIn int) *TokenResponse {
	return NewTokenResponse(BearerTokenType, token, expiresIn)
}

// ParseBearerToken parses and returns the bearer token from a request. It will
// return standard errors if the extraction failed.
//
// Note: The spec also allows obtaining the bearer token from query parameters
// and the request body (form data). This implementation only supports obtaining
// the token from the "Authorization" header as this is the most common use case
// and considered most secure.
func ParseBearerToken(r *http.Request) (string, error) {
	// read header
	h := r.Header.Get("Authorization")

	// split header
	s := strings.SplitN(h, " ", 2)
	if len(s) != 2 || !strings.EqualFold(s[0], BearerTokenType) {
		return "", errors.New("Malformed or missing authorization header")
	}
{'fraction_non_alphanumeric': 0.1012778040700426, 'fraction_numerical': 0.003786086133459536, 'mean_word_length': 4.365482233502538, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1106405', 'n_tokens_mistral': 622, 'n_tokens_neox': 599, 'n_words': 239}