mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-19 01:28:51 +02:00
mcp: token: handle authorization_code request (pt1)
This commit is contained in:
parent
9e4947c62f
commit
625c9d4014
11 changed files with 740 additions and 25 deletions
34
internal/oauth21/token.go
Normal file
34
internal/oauth21/token.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue