social_protocol.go (3674B)
1 package pub 2 3 import ( 4 "context" 5 "net/http" 6 7 "github.com/superseriousbusiness/activity/streams/vocab" 8 ) 9 10 // SocialProtocol contains behaviors an application needs to satisfy for the 11 // full ActivityPub C2S implementation to be supported by this library. 12 // 13 // It is only required if the client application wants to support the client-to- 14 // server, or social, protocol. 15 // 16 // It is passed to the library as a dependency injection from the client 17 // application. 18 type SocialProtocol interface { 19 // Hook callback after parsing the request body for a client request 20 // to the Actor's outbox. 21 // 22 // Can be used to set contextual information based on the 23 // ActivityStreams object received. 24 // 25 // Only called if the Social API is enabled. 26 // 27 // Warning: Neither authentication nor authorization has taken place at 28 // this time. Doing anything beyond setting contextual information is 29 // strongly discouraged. 30 // 31 // If an error is returned, it is passed back to the caller of 32 // PostOutbox. In this case, the DelegateActor implementation must not 33 // write a response to the ResponseWriter as is expected that the caller 34 // to PostOutbox will do so when handling the error. 35 PostOutboxRequestBodyHook(c context.Context, r *http.Request, data vocab.Type) (context.Context, error) 36 // AuthenticatePostOutbox delegates the authentication of a POST to an 37 // outbox. 38 // 39 // Only called if the Social API is enabled. 40 // 41 // If an error is returned, it is passed back to the caller of 42 // PostOutbox. 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 AuthenticatePostOutbox(c context.Context, w http.ResponseWriter, r *http.Request) (out context.Context, authenticated bool, err error) 55 // SocialCallbacks returns the application logic that handles 56 // ActivityStreams received from C2S clients. 57 // 58 // Note that certain types of callbacks will be 'wrapped' with default 59 // behaviors supported natively by the library. Other callbacks 60 // compatible with streams.TypeResolver can be specified by 'other'. 61 // 62 // For example, setting the 'Create' field in the SocialWrappedCallbacks 63 // lets an application dependency inject additional behaviors they want 64 // to take place, including the default behavior supplied by this 65 // library. This is guaranteed to be compliant with the ActivityPub 66 // Social protocol. 67 // 68 // To override the default behavior, instead supply the function in 69 // 'other', which does not guarantee the application will be compliant 70 // with the ActivityPub Social Protocol. 71 // 72 // Applications are not expected to handle every single ActivityStreams 73 // type and extension. The unhandled ones are passed to DefaultCallback. 74 SocialCallbacks(c context.Context) (wrapped SocialWrappedCallbacks, other []interface{}, err error) 75 // DefaultCallback is called for types that go-fed can deserialize but 76 // are not handled by the application's callbacks returned in the 77 // Callbacks method. 78 // 79 // Applications are not expected to handle every single ActivityStreams 80 // type and extension, so the unhandled ones are passed to 81 // DefaultCallback. 82 DefaultCallback(c context.Context, activity Activity) error 83 }