Skip to content
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

Get Principal and other Request information from OperationHandler #203

Open
gcastillo-bakkt opened this issue Jun 20, 2021 · 3 comments
Open

Comments

@gcastillo-bakkt
Copy link

Hi, i'm trying to figure out a way to get the Principal or request context from within the OperationHandler. I need to be able to take the caller's credentials to make a call to a downstream system. Right now, I am able to work around this by defining the api_key as a header parameter but that doesn't play well with swagger-ui and other tools.

@youyuanwu
Copy link
Member

If the info is in the http context object, you can access it.
https://github.com/go-swagger/go-swagger/blob/b49f50b58d021e303ce819ab8310add9bad3a99d/examples/auto-configure/restapi/operations/todos/destroy_one_parameters.go#L29

HTTPRequest.Context()

Can give you the context, and extract the values in side.

@gcastillo-bakkt
Copy link
Author

Thank you for this, I'm using an untyped api though. With this workflow I don't the RequestBinder interface comes into play.

@fredbi
Copy link
Member

fredbi commented Dec 13, 2023

principal := middleware.SecurityPrincipalFrom(req)

should do the job.

Other information is stored in the request context can be extracted with similar helpers:

  • MatchedRouteFrom(req),
  • SecurityScopesFrom(req)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants