User aware action in goa with jwt auth

I am making a web server with goa.

I cannot find a way to get user context inside a controller method. I use JWT auth that is supported by basic auth. I have a JWT secure action that is secured via JWT middleware and it checks passwords and so on.

What I want is to get the username from JWT token to the secure method. Is there any way?

goa design file fragment:

var JWT = JWTSecurity("jwt", func() {
    Scope("api:access", "API access") // Define "api:access" scope

Security(JWT, func() {
    // Use JWT to auth requests to this endpoint
    Scope("api:access") // Enforce presence of "api" scope in JWT claims.

Action("secure", func() {
    Description("This action is secured with the jwt scheme")

and this DSL gets generated into this method:

func (c *JWTSessionsController) Secure(ctx *app.SecureJWTContext) error {
    return ctx.OK(&app.Success{false})

The generated action is secured and works well (Middleware is mounted and all validation passes). But I want to get username inside in the action. Is is somehow possible?

I would like to get it in this way:


For now I will have to parse the jwt twice. :frowning:

Stack overflow link (no new information there): link

I made a helper that parses base64 token claims.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.