<commit_before>// Package oauth2 provides structures and functions to implement OAuth2
// compatible authentication servers. The library can be used with any framework
// and is built on top of the standard Go http library.
package oauth2

import (
	"encoding/json"
	"net/http"
	"net/url"
)

// The available known OAuth2 grant types.
const (
	PasswordGrantType          = "password"
	ClientCredentialsGrantType = "client_credentials"
	AuthorizationCodeGrantType = "authorization_code"
	RefreshTokenGrantType      = "refresh_token"
)

// KnownGrantType returns true if the grant type is a known grant type
// (e.g. password, client credentials, authorization code or refresh token).
func KnownGrantType(str string) bool {
	switch str {
	case PasswordGrantType,
		ClientCredentialsGrantType,
		AuthorizationCodeGrantType,
		RefreshTokenGrantType:
		return true
	}

	return false
}

// The available known OAuth2 response types.
const (
	TokenResponseType = "token"
	CodeResponseType  = "code"
)

// KnownResponseType returns true if the response type is a known response type
// (e.g. token or code).
func KnownResponseType(str string) bool {
	switch str {
	case TokenResponseType, CodeResponseType:
		return true
	}

	return false
}

// Write will encode the specified object as json and write a response to the
// response writer as specified by the OAuth2 spec.
func Write(w http.ResponseWriter, obj interface{}, status int) error {
	// set required headers
	w.Header().Set("Content-Type", "application/json;charset=UTF-8")
	w.Header().Set("Cache-Control", "no-store")
	w.Header().Set("Pragma", "no-cache")

	// set status
	w.WriteHeader(status)

	// write error document<commit_msg>correct wording<commit_after>// Package oauth2 provides structures and functions to implement OAuth2
// compatible authentication servers. The library can be used with any framework
// and is built on top of the standard Go http library.
package oauth2

import (
	"encoding/json"
	"net/http"
	"net/url"
)

// The known OAuth2 grant types.
const (
	PasswordGrantType          = "password"
	ClientCredentialsGrantType = "client_credentials"
	AuthorizationCodeGrantType = "authorization_code"
	RefreshTokenGrantType      = "refresh_token"
)

// KnownGrantType returns true if the grant type is a known grant type
// (e.g. password, client credentials, authorization code or refresh token).
func KnownGrantType(str string) bool {
	switch str {
	case PasswordGrantType,
		ClientCredentialsGrantType,
		AuthorizationCodeGrantType,
		RefreshTokenGrantType:
		return true
	}

	return false
}

// The known OAuth2 response types.
const (
	TokenResponseType = "token"
	CodeResponseType  = "code"
)

// KnownResponseType returns true if the response type is a known response type
// (e.g. token or code).
func KnownResponseType(str string) bool {
	switch str {
	case TokenResponseType, CodeResponseType:
		return true
	}

	return false
}

// Write will encode the specified object as json and write a response to the
// response writer as specified by the OAuth2 spec.
func Write(w http.ResponseWriter, obj interface{}, status int) error {
	// set required headers
	w.Header().Set("Content-Type", "application/json;charset=UTF-8")
	w.Header().Set("Cache-Control", "no-store")
	w.Header().Set("Pragma", "no-cache")

	// set status
	w.WriteHeader(status)

	// write error document
{'fraction_non_alphanumeric': 0.09009546539379475, 'fraction_numerical': 0.004176610978520286, 'mean_word_length': 4.206521739130435, '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': '5843463', 'n_tokens_mistral': 1001, 'n_tokens_neox': 955, 'n_words': 346}