GenerateClientName generates a client name if not provided
()
| 498 | |
| 499 | // GenerateClientName generates a client name if not provided |
| 500 | func (req *OAuth2ClientRegistrationRequest) GenerateClientName() string { |
| 501 | if req.ClientName != "" { |
| 502 | // Ensure client name fits database constraint (varchar(64)) |
| 503 | if len(req.ClientName) > 64 { |
| 504 | // Preserve uniqueness by including a hash of the original name |
| 505 | hash := fmt.Sprintf("%x", sha256.Sum256([]byte(req.ClientName)))[:8] |
| 506 | maxPrefix := 64 - 1 - len(hash) // 1 for separator |
| 507 | return req.ClientName[:maxPrefix] + "-" + hash |
| 508 | } |
| 509 | return req.ClientName |
| 510 | } |
| 511 | |
| 512 | // Try to derive from client_uri |
| 513 | if req.ClientURI != "" { |
| 514 | if uri, err := url.Parse(req.ClientURI); err == nil && uri.Host != "" { |
| 515 | name := fmt.Sprintf("Client (%s)", uri.Host) |
| 516 | if len(name) > 64 { |
| 517 | return name[:64] |
| 518 | } |
| 519 | return name |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | // Try to derive from first redirect URI |
| 524 | if len(req.RedirectURIs) > 0 { |
| 525 | if uri, err := url.Parse(req.RedirectURIs[0]); err == nil && uri.Host != "" { |
| 526 | name := fmt.Sprintf("Client (%s)", uri.Host) |
| 527 | if len(name) > 64 { |
| 528 | return name[:64] |
| 529 | } |
| 530 | return name |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | return "Dynamically Registered Client" |
| 535 | } |
| 536 | |
| 537 | // OAuth2ClientRegistrationResponse represents RFC 7591 Dynamic Client Registration Response. |
| 538 | type OAuth2ClientRegistrationResponse struct { |
no test coverage detected