complete interface docs
This commit is contained in:
parent
cf3a87c4c3
commit
c340ed9ed5
1 changed files with 39 additions and 10 deletions
|
@ -42,23 +42,28 @@ func (e StatusError) Is(err error) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Request[T any] struct {
|
type Request[T any] struct {
|
||||||
Method string
|
Method string
|
||||||
URL *url.URL
|
URL *url.URL
|
||||||
Header http.Header
|
Header http.Header
|
||||||
Form url.Values
|
Form url.Values
|
||||||
Data *T
|
PostForm url.Values
|
||||||
|
Data *T
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRequest[T any](r *http.Request, data *T) *Request[T] {
|
func newRequest[T any](r *http.Request, data *T) *Request[T] {
|
||||||
return &Request[T]{
|
return &Request[T]{
|
||||||
Method: r.Method,
|
Method: r.Method,
|
||||||
URL: r.URL,
|
URL: r.URL,
|
||||||
Header: r.Header,
|
Header: r.Header,
|
||||||
Form: r.Form,
|
Form: r.Form,
|
||||||
Data: data,
|
PostForm: r.PostForm,
|
||||||
|
Data: data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClientRequest is a Request with a verified client attached to it.
|
||||||
|
// Methods the recieve this argument may assume the client was authenticated,
|
||||||
|
// or verified to be a public client.
|
||||||
type ClientRequest[T any] struct {
|
type ClientRequest[T any] struct {
|
||||||
*Request[T]
|
*Request[T]
|
||||||
Client Client
|
Client Client
|
||||||
|
@ -102,6 +107,28 @@ type Redirect struct {
|
||||||
Params url.Values
|
Params url.Values
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Server describes the inferface that needs to be implemented to serve
|
||||||
|
// openID Connect and Oauth2 standard requests.
|
||||||
|
//
|
||||||
|
// Methods are called after the HTTP route is resolved and
|
||||||
|
// the request body is parsed into the Request's Data field.
|
||||||
|
// When a method is called, it can be assumed that required fields,
|
||||||
|
// as described in their relavant standard, are validated already.
|
||||||
|
// The Response Data field may be of any type to allow flexibilty
|
||||||
|
// to extend responses with custom fields. There are however requirements
|
||||||
|
// in the standards regarding the repsonse models. Where applicable
|
||||||
|
// the method documentation gives a recommodated type which can be used
|
||||||
|
// directly or extended upon.
|
||||||
|
//
|
||||||
|
// In short it is the scope of this framework to:
|
||||||
|
// - Route requests to their methods;
|
||||||
|
// - Parse request data into a type that represents the model from the standards;
|
||||||
|
// - Validate required fields in the request;
|
||||||
|
// - Provide utility functions that help implementors build the response;
|
||||||
|
//
|
||||||
|
// It is in the scope of the implementor:
|
||||||
|
// - Handle the request data to obtain or modify state in their storage / database;
|
||||||
|
// - Implement the business logic that is needed to build the response;
|
||||||
type Server interface {
|
type Server interface {
|
||||||
// Health should return a status of "ok" once the Server is listining.
|
// Health should return a status of "ok" once the Server is listining.
|
||||||
// The recommended Response Data type is [Status].
|
// The recommended Response Data type is [Status].
|
||||||
|
@ -208,6 +235,8 @@ type Server interface {
|
||||||
// The recommended Response Data type is [jose.JSOMWebKeySet].
|
// The recommended Response Data type is [jose.JSOMWebKeySet].
|
||||||
Keys(context.Context, *Request[struct{}]) (*Response, error)
|
Keys(context.Context, *Request[struct{}]) (*Response, error)
|
||||||
|
|
||||||
|
// mustImpl forces implementations to embed the UnimplementedServer for forward
|
||||||
|
// compatibilty with the interface.
|
||||||
mustImpl()
|
mustImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue