mcp: token: handle authorization_code request (pt1) (#5587)

This commit is contained in:
Denis Mishin 2025-04-28 14:09:22 -04:00 committed by GitHub
parent b7dbc8e467
commit 7b9c392531
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 722 additions and 25 deletions

34
internal/oauth21/token.go Normal file
View file

@ -0,0 +1,34 @@
package oauth21
import (
"fmt"
"net/http"
"github.com/bufbuild/protovalidate-go"
"github.com/pomerium/pomerium/internal/oauth21/gen"
)
func ParseTokenRequest(r *http.Request) (*gen.TokenRequest, error) {
err := r.ParseForm()
if err != nil {
return nil, fmt.Errorf("failed to parse form: %w", err)
}
v := &gen.TokenRequest{
GrantType: r.Form.Get("grant_type"),
Code: optionalFormParam(r, "code"),
CodeVerifier: optionalFormParam(r, "code_verifier"),
ClientId: optionalFormParam(r, "client_id"),
RefreshToken: optionalFormParam(r, "refresh_token"),
Scope: optionalFormParam(r, "scope"),
ClientSecret: optionalFormParam(r, "client_secret"),
}
err = protovalidate.Validate(v)
if err != nil {
return nil, fmt.Errorf("failed to validate token request: %w", err)
}
return v, nil
}