// WriteIntrospectionError responds with token metadata discovered by token introspection as defined in
// https://tools.ietf.org/search/rfc7662#section-2.2
//
// If the protected resource uses OAuth 2.0 client credentials to
// authenticate to the introspection endpoint and its credentials are
// invalid, the authorization server responds with an HTTP 401
// (Unauthorized) as described in Section 5.2 of OAuth 2.0 [RFC6749].
//
// If the protected resource uses an OAuth 2.0 bearer token to authorize
// its call to the introspection endpoint and the token used for
// authorization does not contain sufficient privileges or is otherwise
// invalid for this request, the authorization server responds with an
// HTTP 401 code as described in Section 3 of OAuth 2.0 Bearer Token
// Usage [RFC6750].
//
// Note that a properly formed and authorized query for an inactive or
// otherwise invalid token (or a token the protected resource is not
// allowed to know about) is not considered an error response by this
// specification.  In these cases, the authorization server MUST instead
// respond with an introspection response with the "active" field set to
// "false" as described in Section 2.2.


If the protected resource uses OAuth 2.0 client credentials to
authenticate to the introspection endpoint and its credentials are
invalid, the authorization server responds with an HTTP 401
(Unauthorized) as described in Section 5.2 of OAuth 2.0 [RFC6749].

If the protected resource uses an OAuth 2.0 bearer token to authorize
its call to the introspection endpoint and the token used for
authorization does not contain sufficient privileges or is otherwise
invalid for this request, the authorization server responds with an
HTTP 401 code as described in Section 3 of OAuth 2.0 Bearer Token
Usage [RFC6750].

Note that a properly formed and authorized query for an inactive or
otherwise invalid token (or a token the protected resource is not
allowed to know about) is not considered an error response by this
specification.  In these cases, the authorization server MUST instead
respond with an introspection response with the "active" field set to
"false" as described in Section 2.2.
// WriteIntrospectionError responds with token metadata discovered by token introspection as defined in // https : // tools . ietf . org / search / rfc7662#section - 2 . 2 // // If the protected resource uses OAuth 2 . 0 client credentials to // authenticate to the introspection endpoint and its credentials are // invalid the authorization server responds with an HTTP 401 // ( Unauthorized ) as described in Section 5 . 2 of OAuth 2 . 0 [ RFC6749 ] . // // If the protected resource uses an OAuth 2 . 0 bearer token to authorize // its call to the introspection endpoint and the token used for // authorization does not contain sufficient privileges or is otherwise // invalid for this request the authorization server responds with an // HTTP 401 code as described in Section 3 of OAuth 2 . 0 Bearer Token // Usage [ RFC6750 ] . // // Note that a properly formed and authorized query for an inactive or // otherwise invalid token ( or a token the protected resource is not // allowed to know about ) is not considered an error response by this // specification . In these cases the authorization server MUST instead // respond with an introspection response with the " active " field set to // " false " as described in Section 2 . 2 .
func (f *Fosite) WriteIntrospectionError(rw http.ResponseWriter, err error) {
	if err == nil {
		return
	}
	switch errors.Cause(err) {
	case ErrInvalidRequest, ErrRequestUnauthorized:
		writeJsonError(rw, err)
		return
	}
	rw.Header().Set("Content-Type", "application/json;charset=UTF-8")
	_ = json.NewEncoder(rw).Encode(struct {
		Active bool `json:"active"`
	}{Active: false})
}
func ( f * Fosite ) WriteIntrospectionError ( rw http . ResponseWriter , err error ) { if err == nil { return } switch errors . Cause ( err ) { case ErrInvalidRequest , ErrRequestUnauthorized : writeJsonError ( rw , err ) return } rw . Header ( ) . Set ( " " , " " ) _ = json . NewEncoder ( rw ) . Encode ( struct { Active bool `json:"active"` } { Active : false } ) }