65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"somehole.com/service/oauth2/session"
|
|
"somehole.com/service/router"
|
|
)
|
|
|
|
type CallbackRequestBuilder struct {
|
|
*router.DefaultRequestBuilder
|
|
values struct {
|
|
router.Values
|
|
State session.State `form:"state"`
|
|
Code session.Code `form:"code"`
|
|
}
|
|
}
|
|
|
|
func (*CallbackRequestBuilder) Prototype() router.PrototypeRequestBuilder {
|
|
rb := CallbackRequestBuilder{}
|
|
rb.DefaultRequestBuilder = router.NewDefaultRequestBuilder().
|
|
SetErrorHandler(&ErrorHandler{}).
|
|
SetValues(&rb.values.Values, &rb.values).
|
|
SetDefaults()
|
|
return rb
|
|
}
|
|
|
|
func (rb CallbackRequestBuilder) RequestBuilder() router.RequestBuilder {
|
|
return &rb
|
|
}
|
|
|
|
type CallbackResponse struct {
|
|
*router.DefaultResponse
|
|
Body struct {
|
|
router.Body
|
|
Message string `json:"message"`
|
|
}
|
|
}
|
|
|
|
func (*CallbackResponse) Prototype() router.PrototypeResponse {
|
|
r := CallbackResponse{}
|
|
r.DefaultResponse = router.NewDefaultResponse().
|
|
SetBody(&r.Body.Body, &r.Body).
|
|
SetDefaults()
|
|
return r
|
|
}
|
|
|
|
func (r CallbackResponse) Response() router.Response {
|
|
return &r
|
|
}
|
|
|
|
type UnimplementedCallbackServer struct {
|
|
*ErrorHandler
|
|
}
|
|
|
|
func (UnimplementedCallbackServer) mustEmbedUnimplementedCallbackServer() {}
|
|
|
|
func (u UnimplementedCallbackServer) Callback(req *CallbackRequestBuilder) (res *CallbackResponse, errRes router.ErrorResponse) {
|
|
errRes = u.ErrorResponse(router.DefaultErrorNotImplemented)
|
|
return
|
|
}
|
|
|
|
type CallbackServer interface {
|
|
mustEmbedUnimplementedCallbackServer()
|
|
Callback(req *CallbackRequestBuilder) (res *CallbackResponse, errRes router.ErrorResponse)
|
|
}
|