oauth2/server/token.go

53 lines
1.5 KiB
Go

package server
import (
"somehole.com/service/oauth2/session"
"somehole.com/service/router"
)
type TokenRequestBuilder struct {
router.DefaultRequestBuilder
values struct {
router.Values
ResponseType string `form:"response_type"`
ClientId string `form:"client_id"`
Code session.Code `form:"code"`
}
}
func (rb TokenRequestBuilder) RequestBuilder() router.RequestBuilder {
rb.DefaultRequestBuilder = router.NewDefaultRequestBuilder(&rb, TokenRequestBuilder{}, &ErrorHandler{}, nil, nil, nil, &rb.values.Values, &rb.values, nil, nil)
return &rb
}
type TokenResponse struct {
router.DefaultResponse
Body struct {
router.Body
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"`
}
}
func (r TokenResponse) Response() router.Response {
r.DefaultResponse = router.NewDefaultResponse(&r, TokenResponse{}, nil, nil, &r.Body.Body, &r.Body)
return &r
}
type UnimplementedTokenServer struct{}
func (UnimplementedTokenServer) mustEmbedUnimplementedTokenServer() {}
func (UnimplementedTokenServer) Token(req *TokenRequestBuilder) (res *TokenResponse, errRes router.ErrorResponse) {
errRes = &ErrorHandler{router.DefaultErrorNotImplemented}
return
}
type TokenServer interface {
mustEmbedUnimplementedTokenServer()
Token(req *TokenRequestBuilder) (res *TokenResponse, errRes router.ErrorResponse)
}