diff options
author | 2022-11-14 09:30:01 +0000 | |
---|---|---|
committer | 2022-11-14 10:30:01 +0100 | |
commit | d120743e8bee74bbb6381a6ec017d7fa62b3f13e (patch) | |
tree | 166ab39f161b77cf6055abcc26de370c932c474f /internal/api/client | |
parent | [chore]: Bump codeberg.org/gruf/go-cache/v3 from 3.1.7 to 3.1.8 (#1043) (diff) | |
download | gotosocial-d120743e8bee74bbb6381a6ec017d7fa62b3f13e.tar.xz |
[feature] add instance-expose-public-timeline flag (#1039)
* Add instance-expose-public-timeline flag
Adds a config flag that allows unauthenticated access to /api/v1/timelines/public. Defaults to false to replicate existing behaviour.
* Update structure following review
* Add comment
* Fix linting
Diffstat (limited to 'internal/api/client')
-rw-r--r-- | internal/api/client/timeline/public.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/internal/api/client/timeline/public.go b/internal/api/client/timeline/public.go index 673c20a99..a2e1faf59 100644 --- a/internal/api/client/timeline/public.go +++ b/internal/api/client/timeline/public.go @@ -25,6 +25,7 @@ import ( "github.com/gin-gonic/gin" "github.com/superseriousbusiness/gotosocial/internal/api" + "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/oauth" ) @@ -110,7 +111,17 @@ import ( // '400': // description: bad request func (m *Module) PublicTimelineGETHandler(c *gin.Context) { - authed, err := oauth.Authed(c, true, true, true, true) + var authed *oauth.Auth + var err error + + if config.GetInstanceExposePublicTimeline() { + // If the public timeline is allowed to be exposed, still check if we + // can extract various authentication properties, but don't require them. + authed, err = oauth.Authed(c, false, false, false, false) + } else { + authed, err = oauth.Authed(c, true, true, true, true) + } + if err != nil { api.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) return |