oauth2/server/token.go

53 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 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 01:27:53 +00:00
func (rb TokenRequestBuilder) RequestBuilder() router.RequestBuilder {
2024-10-09 05:07:57 +00:00
rb.DefaultRequestBuilder = router.NewDefaultRequestBuilder(&rb, TokenRequestBuilder{}, &ErrorHandler{}, nil, nil, nil, &rb.values.Values, &rb.values, nil, nil)
2024-10-09 01:27:53 +00:00
return &rb
}
2024-10-09 00:33:23 +00:00
type TokenResponse struct {
2024-10-09 04:14:54 +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 04:14:54 +00:00
func (r TokenResponse) Response() router.Response {
2024-10-09 05:07:57 +00:00
r.DefaultResponse = router.NewDefaultResponse(&r, TokenResponse{}, nil, nil, &r.Body.Body, &r.Body)
2024-10-09 04:14:54 +00:00
return &r
2024-10-01 17:38:43 +00:00
}
type UnimplementedTokenServer struct{}
2024-10-09 00:33:23 +00:00
func (UnimplementedTokenServer) mustEmbedUnimplementedTokenServer() {}
2024-10-01 17:38:43 +00:00
2024-10-09 00:33:23 +00:00
func (UnimplementedTokenServer) Token(req *TokenRequestBuilder) (res *TokenResponse, errRes router.ErrorResponse) {
2024-10-09 05:07:57 +00:00
errRes = &ErrorHandler{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
}