oauth2/server/callback.go

56 lines
1.2 KiB
Go
Raw Normal View History

2024-10-01 17:38:43 +00:00
package server
import (
2024-10-09 01:24:55 +00:00
"encoding/json"
2024-10-01 17:38:43 +00:00
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 01:24:55 +00:00
router.UnimplementedRequestBuilder
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 01:27:53 +00:00
func (rb CallbackRequestBuilder) RequestBuilder() router.RequestBuilder {
return &rb
}
2024-10-09 01:24:55 +00:00
func (rb *CallbackRequestBuilder) Values(values router.Values) (errRes router.ErrorResponse) {
err := rb.values.Values.Parse(values)
2024-10-09 00:33:23 +00:00
if err != nil {
return ErrorBadRequest
}
return Ok
2024-10-01 22:57:46 +00:00
}
2024-10-09 00:33:23 +00:00
type CallbackResponse struct {
2024-10-09 01:24:55 +00:00
router.UnimplementedResponse
2024-10-09 00:33:23 +00:00
Body struct {
Message string `json:"message"`
2024-10-01 17:38:43 +00:00
}
}
2024-10-09 01:24:55 +00:00
func (r *CallbackResponse) BodyBytes() (body []byte) {
body, _ = json.Marshal(r.Body)
return
2024-10-01 17:38:43 +00:00
}
type UnimplementedCallbackServer struct{}
2024-10-09 00:33:23 +00:00
func (UnimplementedCallbackServer) mustEmbedUnimplementedCallbackServer() {}
2024-10-01 17:38:43 +00:00
2024-10-09 00:33:23 +00:00
func (UnimplementedCallbackServer) Callback(req *CallbackRequestBuilder) (res *CallbackResponse, errRes router.ErrorResponse) {
errRes = ErrorNotImplemented
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
}