From 0bd58d61e547f482dd3c38a30fccb4c58caf2a67 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Sat, 21 Aug 2021 04:16:45 +0200 Subject: Added introspection endpoint. (#16752) Co-authored-by: Lunny Xiao --- services/auth/oauth2.go | 12 +++++++++++- services/forms/user_form.go | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'services') diff --git a/services/auth/oauth2.go b/services/auth/oauth2.go index 93806c7072..f7f870dade 100644 --- a/services/auth/oauth2.go +++ b/services/auth/oauth2.go @@ -113,7 +113,7 @@ func (o *OAuth2) Verify(req *http.Request, w http.ResponseWriter, store DataStor return nil } - if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) { + if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isAuthenticatedTokenRequest(req) { return nil } @@ -134,3 +134,13 @@ func (o *OAuth2) Verify(req *http.Request, w http.ResponseWriter, store DataStor log.Trace("OAuth2 Authorization: Logged in user %-v", user) return user } + +func isAuthenticatedTokenRequest(req *http.Request) bool { + switch req.URL.Path { + case "/login/oauth/userinfo": + fallthrough + case "/login/oauth/introspect": + return true + } + return false +} diff --git a/services/forms/user_form.go b/services/forms/user_form.go index 1e12795c70..7d6b976936 100644 --- a/services/forms/user_form.go +++ b/services/forms/user_form.go @@ -215,6 +215,17 @@ func (f *AccessTokenForm) Validate(req *http.Request, errs binding.Errors) bindi return middleware.Validate(errs, ctx.Data, f, ctx.Locale) } +// IntrospectTokenForm for introspecting tokens +type IntrospectTokenForm struct { + Token string `json:"token"` +} + +// Validate validates the fields +func (f *IntrospectTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors { + ctx := context.GetContext(req) + return middleware.Validate(errs, ctx.Data, f, ctx.Locale) +} + // __________________________________________.___ _______ ________ _________ // / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/ // \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \ -- cgit v1.2.3