2021-05-04 22:06:05 +00:00
package handlers
import (
"net/http"
2022-03-15 22:55:38 +00:00
"github.com/ory/fosite"
2021-08-11 01:04:35 +00:00
"github.com/authelia/authelia/v4/internal/middlewares"
2022-03-15 22:55:38 +00:00
"github.com/authelia/authelia/v4/internal/oidc"
2021-05-04 22:06:05 +00:00
)
2022-04-07 00:58:51 +00:00
// OAuthIntrospectionPOST handles POST requests to the OAuth 2.0 Introspection endpoint.
//
// https://datatracker.ietf.org/doc/html/rfc7662
func OAuthIntrospectionPOST ( ctx * middlewares . AutheliaCtx , rw http . ResponseWriter , req * http . Request ) {
2022-03-15 22:55:38 +00:00
var (
responder fosite . IntrospectionResponder
err error
)
oidcSession := oidc . NewSession ( )
2022-10-20 02:16:36 +00:00
if responder , err = ctx . Providers . OpenIDConnect . NewIntrospectionRequest ( ctx , req , oidcSession ) ; err != nil {
2022-03-15 22:55:38 +00:00
rfc := fosite . ErrorToRFC6749Error ( err )
2021-05-04 22:06:05 +00:00
2022-04-25 00:31:05 +00:00
ctx . Logger . Errorf ( "Introspection Request failed with error: %s" , rfc . WithExposeDebug ( true ) . GetDescription ( ) )
2021-05-04 22:06:05 +00:00
2022-11-13 03:26:10 +00:00
ctx . Providers . OpenIDConnect . WriteIntrospectionError ( ctx , rw , err )
2021-05-04 22:06:05 +00:00
return
}
2022-03-15 22:55:38 +00:00
requester := responder . GetAccessRequester ( )
ctx . Logger . Tracef ( "Introspection Request yeilded a %s (active: %t) requested at %s created with request id '%s' on client with id '%s'" , responder . GetTokenUse ( ) , responder . IsActive ( ) , requester . GetRequestedAt ( ) . String ( ) , requester . GetID ( ) , requester . GetClient ( ) . GetID ( ) )
2022-11-13 03:26:10 +00:00
ctx . Providers . OpenIDConnect . WriteIntrospectionResponse ( ctx , rw , responder )
2021-05-04 22:06:05 +00:00
}