oauth2/server/token.go
2024-10-08 21:27:53 -04:00

61 lines
1.5 KiB
Go

package server
import (
"encoding/json"
"somehole.com/service/oauth2/session"
"somehole.com/service/router"
)
type TokenRequestBuilder struct {
router.UnimplementedRequestBuilder
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 {
return &rb
}
func (rb *TokenRequestBuilder) Values(values router.Values) (errRes router.ErrorResponse) {
err := rb.values.Values.Parse(values)
if err != nil {
return ErrorBadRequest
}
return Ok
}
type TokenResponse struct {
router.UnimplementedResponse
Body struct {
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) BodyBytes() (body []byte) {
body, _ = json.Marshal(r.Body)
return
}
type UnimplementedTokenServer struct{}
func (UnimplementedTokenServer) mustEmbedUnimplementedTokenServer() {}
func (UnimplementedTokenServer) Token(req *TokenRequestBuilder) (res *TokenResponse, errRes router.ErrorResponse) {
errRes = ErrorNotImplemented
return
}
type TokenServer interface {
mustEmbedUnimplementedTokenServer()
Token(req *TokenRequestBuilder) (res *TokenResponse, errRes router.ErrorResponse)
}