package server import ( "io" "somehole.com/service/oauth2/session" "somehole.com/service/router" ) type TokenRequestBuilder struct { allowedMethods []string header struct { router.Header } values struct { router.Values ResponseType string `form:"response_type"` ClientId string `form:"client_id"` Code session.Code `form:"code"` } } func (trb TokenRequestBuilder) RequestBuilder() router.RequestBuilder { return &trb } func (trb *TokenRequestBuilder) Allowed(method string) (errRes router.ErrorResponse) { var ok bool for _, m := range trb.allowedMethods { if m == method { ok = true } } if !ok { return ErrorMethodNotAllowed } return Ok } func (trb *TokenRequestBuilder) Header(header router.Header) (errRes router.ErrorResponse) { err := trb.header.Header.Parse(header) if err != nil { return ErrorBadRequest } return Ok } func (trb *TokenRequestBuilder) Body(body io.ReadCloser) (errRes router.ErrorResponse) { defer body.Close() return Ok } func (trb *TokenRequestBuilder) Values(values router.Values) (errRes router.ErrorResponse) { err := trb.values.Values.Parse(values) if err != nil { return ErrorBadRequest } return Ok } type TokenResponse struct { header struct { router.Header } 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 (tr TokenResponse) Response() router.Response { return &tr } func (tr *TokenResponse) Header() (header router.Header) { if tr.header.Header == nil { tr.header.Header.Parse(tr.header) } return tr.header.Header } func (tr *TokenResponse) Bytes() []byte { return mustMarshalJson(tr.Body) } type UnimplementedTokenServer struct{} func (UnimplementedTokenServer) mustEmbedUnimplementedTokenServer() {} func (UnimplementedTokenServer) Token(req *TokenRequestBuilder) (res *TokenResponse, errRes router.ErrorResponse) { errRes = ErrorNotImplemented return } type TokenServer interface { mustEmbedUnimplementedTokenServer() Token(*TokenRequestBuilder) (*TokenResponse, router.ErrorResponse) }