oauth2/server/callback.go

65 lines
1.5 KiB
Go
Raw Normal View History

2024-10-01 17:38:43 +00:00
package server
import (
2024-10-09 00:33:23 +00:00
"somehole.com/service/oauth2/session"
"somehole.com/service/router"
2024-10-01 17:38:43 +00:00
)
2024-10-09 00:33:23 +00:00
type CallbackRequestBuilder struct {
2024-10-09 13:58:26 +00:00
*router.DefaultRequestBuilder
2024-10-09 00:33:23 +00:00
values struct {
router.Values
State session.State `form:"state"`
Code session.Code `form:"code"`
}
2024-10-01 17:38:43 +00:00
}
2024-10-09 13:58:26 +00:00
func (*CallbackRequestBuilder) Prototype() router.PrototypeRequestBuilder {
rb := CallbackRequestBuilder{}
rb.DefaultRequestBuilder = router.NewDefaultRequestBuilder().
SetErrorHandler(&ErrorHandler{}).
SetValues(&rb.values.Values, &rb.values).
SetDefaults()
return rb
}
2024-10-09 01:27:53 +00:00
func (rb CallbackRequestBuilder) RequestBuilder() router.RequestBuilder {
return &rb
}
2024-10-09 00:33:23 +00:00
type CallbackResponse struct {
2024-10-09 13:58:26 +00:00
*router.DefaultResponse
2024-10-09 00:33:23 +00:00
Body struct {
2024-10-09 04:14:54 +00:00
router.Body
2024-10-09 00:33:23 +00:00
Message string `json:"message"`
2024-10-01 17:38:43 +00:00
}
}
2024-10-09 13:58:26 +00:00
func (*CallbackResponse) Prototype() router.PrototypeResponse {
r := CallbackResponse{}
r.DefaultResponse = router.NewDefaultResponse().
SetBody(&r.Body.Body, &r.Body).
SetDefaults()
return r
}
2024-10-09 04:14:54 +00:00
func (r CallbackResponse) Response() router.Response {
return &r
2024-10-01 17:38:43 +00:00
}
type UnimplementedCallbackServer struct {
*ErrorHandler
}
2024-10-01 17:38:43 +00:00
2024-10-09 00:33:23 +00:00
func (UnimplementedCallbackServer) mustEmbedUnimplementedCallbackServer() {}
2024-10-01 17:38:43 +00:00
func (u UnimplementedCallbackServer) Callback(req *CallbackRequestBuilder) (res *CallbackResponse, errRes router.ErrorResponse) {
errRes = u.ErrorResponse(router.DefaultErrorNotImplemented)
2024-10-01 17:38:43 +00:00
return
}
type CallbackServer interface {
mustEmbedUnimplementedCallbackServer()
2024-10-09 00:50:05 +00:00
Callback(req *CallbackRequestBuilder) (res *CallbackResponse, errRes router.ErrorResponse)
2024-10-01 17:38:43 +00:00
}