Skip to content

feat: Custom security schemes #1463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jeanschmitt
Copy link
Contributor

Summary

Addresses a FIXME (in parse_security.go) about a too strict authentication schemes enum validation.

This PR introduces a new configuration field, authentication_schemes, used to configure allowed authentication schemes.
By default, the ones defined in https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml are considered.

In addition, a security type is generated for custom securities, making it possible to access the Roles defined in the specification from custom security implementations (which is especially useful with non-standard authentication schemes).

Breaking change

This PR introduces a breaking change in the generated SecurityHandler signature for custom securities:

type SecurityHandler interface {
	HandleCustom(ctx context.Context, operationName OperationName, req *http.Request) (context.Context, error)
}

// becomes

type SecurityHandler interface {
	HandleCustom(ctx context.Context, operationName OperationName, t Custom) (context.Context, error)
}

type Custom struct {
	Request *http.Request
	Roles   []string
}

I think this change is worth it, because it has little impact (req => t.Request), and facilitates future extensions for custom securities.

@jeanschmitt jeanschmitt marked this pull request as draft May 22, 2025 19:59
@jeanschmitt jeanschmitt force-pushed the custom-security-schemes branch from d3251d3 to 9f4501f Compare May 22, 2025 20:04
@jeanschmitt jeanschmitt marked this pull request as ready for review May 22, 2025 20:07
@jeanschmitt jeanschmitt changed the title Custom security schemes feat: Custom security schemes May 22, 2025
@jeanschmitt jeanschmitt force-pushed the custom-security-schemes branch from 6e39e43 to a6beeb2 Compare June 15, 2025 09:07
@jeanschmitt jeanschmitt force-pushed the custom-security-schemes branch from a6beeb2 to fa69177 Compare July 16, 2025 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant