oauth2/server/token.go

70 lines
1.7 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 TokenRequestBuilder struct {
2024-10-09 04:14:54 +00:00
router.DefaultRequestBuilder
2024-10-09 00:33:23 +00:00
values struct {
router.Values
ResponseType string `form:"response_type"`
ClientId string `form:"client_id"`
Code session.Code `form:"code"`
}
2024-10-01 17:38:43 +00:00
}
2024-10-09 13:58:26 +00:00
func (*TokenRequestBuilder) 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 TokenRequestBuilder) RequestBuilder() router.RequestBuilder {
return &rb
}
2024-10-09 00:33:23 +00:00
type TokenResponse 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
VerificationUri string `json:"verification_uri"`
UserCode session.Code `json:"user_code"`
DeviceCode session.Code `json:"device_code"`
Interval int `json:"interval"`
ExpiresIn int `json:"expires_in"`
2024-10-01 17:38:43 +00:00
}
}
2024-10-09 13:58:26 +00:00
func (*TokenResponse) Prototype() router.PrototypeResponse {
r := TokenResponse{}
r.DefaultResponse = router.NewDefaultResponse().
SetBody(&r.Body.Body, &r.Body).
SetDefaults()
return r
}
2024-10-09 04:14:54 +00:00
func (r TokenResponse) Response() router.Response {
return &r
2024-10-01 17:38:43 +00:00
}
type UnimplementedTokenServer struct {
*ErrorHandler
}
2024-10-01 17:38:43 +00:00
2024-10-09 00:33:23 +00:00
func (UnimplementedTokenServer) mustEmbedUnimplementedTokenServer() {}
2024-10-01 17:38:43 +00:00
func (u UnimplementedTokenServer) Token(req *TokenRequestBuilder) (res *TokenResponse, errRes router.ErrorResponse) {
errRes = u.ErrorResponse(router.DefaultErrorNotImplemented)
2024-10-01 17:38:43 +00:00
return
}
type TokenServer interface {
mustEmbedUnimplementedTokenServer()
2024-10-09 00:50:05 +00:00
Token(req *TokenRequestBuilder) (res *TokenResponse, errRes router.ErrorResponse)
2024-10-01 17:38:43 +00:00
}