gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commonbehavior.go (4162B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package federation
     19 
     20 import (
     21 	"context"
     22 	"net/http"
     23 
     24 	"github.com/superseriousbusiness/activity/streams"
     25 	"github.com/superseriousbusiness/activity/streams/vocab"
     26 )
     27 
     28 /*
     29 	GOFED COMMON BEHAVIOR INTERFACE
     30 	Contains functions required for both the Social API and Federating Protocol.
     31 	It is passed to the library as a dependency injection from the client
     32 	application.
     33 */
     34 
     35 // AuthenticateGetInbox delegates the authentication of a GET to an
     36 // inbox.
     37 //
     38 // Always called, regardless whether the Federated Protocol or Social
     39 // API is enabled.
     40 //
     41 // If an error is returned, it is passed back to the caller of
     42 // GetInbox. In this case, the implementation must not write a
     43 // response to the ResponseWriter as is expected that the client will
     44 // do so when handling the error. The 'authenticated' is ignored.
     45 //
     46 // If no error is returned, but authentication or authorization fails,
     47 // then authenticated must be false and error nil. It is expected that
     48 // the implementation handles writing to the ResponseWriter in this
     49 // case.
     50 //
     51 // Finally, if the authentication and authorization succeeds, then
     52 // authenticated must be true and error nil. The request will continue
     53 // to be processed.
     54 func (f *federator) AuthenticateGetInbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (context.Context, bool, error) {
     55 	// IMPLEMENTATION NOTE: For GoToSocial, we serve GETS to outboxes and inboxes through
     56 	// the CLIENT API, not through the federation API, so we just do nothing here.
     57 	return ctx, false, nil
     58 }
     59 
     60 // AuthenticateGetOutbox delegates the authentication of a GET to an
     61 // outbox.
     62 //
     63 // Always called, regardless whether the Federated Protocol or Social
     64 // API is enabled.
     65 //
     66 // If an error is returned, it is passed back to the caller of
     67 // GetOutbox. In this case, the implementation must not write a
     68 // response to the ResponseWriter as is expected that the client will
     69 // do so when handling the error. The 'authenticated' is ignored.
     70 //
     71 // If no error is returned, but authentication or authorization fails,
     72 // then authenticated must be false and error nil. It is expected that
     73 // the implementation handles writing to the ResponseWriter in this
     74 // case.
     75 //
     76 // Finally, if the authentication and authorization succeeds, then
     77 // authenticated must be true and error nil. The request will continue
     78 // to be processed.
     79 func (f *federator) AuthenticateGetOutbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (context.Context, bool, error) {
     80 	// IMPLEMENTATION NOTE: For GoToSocial, we serve GETS to outboxes and inboxes through
     81 	// the CLIENT API, not through the federation API, so we just do nothing here.
     82 	return ctx, false, nil
     83 }
     84 
     85 // GetOutbox returns the OrderedCollection inbox of the actor for this
     86 // context. It is up to the implementation to provide the correct
     87 // collection for the kind of authorization given in the request.
     88 //
     89 // AuthenticateGetOutbox will be called prior to this.
     90 //
     91 // Always called, regardless whether the Federated Protocol or Social
     92 // API is enabled.
     93 func (f *federator) GetOutbox(ctx context.Context, r *http.Request) (vocab.ActivityStreamsOrderedCollectionPage, error) {
     94 	// IMPLEMENTATION NOTE: For GoToSocial, we serve GETS to outboxes and inboxes through
     95 	// the CLIENT API, not through the federation API, so we just do nothing here.
     96 	return streams.NewActivityStreamsOrderedCollectionPage(), nil
     97 }