goadesign / goadesign/goa

The JWTAuth security scheme should get the token from Cookie as well

Open
#2,965 5 comments 0 reactions 0 assignees View on GitHub
no-issue-activity
Dominant language
Go
Stars
6.1k
Forks
583
Avg merge
2d 10h
Merged PRs (30d)
15

Description

Currently the JWTAuth security scheme assumes the token from the HTTP header only

With the latest release of adding cookie in the design, the The JWTAuth security scheme should be able to read the token from cookie also

For example

```bash
var _ = Service("rating", func() {
Description("The rating service exposes endpoints to read and write user's rating for resources")

Error("not-found", ErrorResult, "Resource Not Found Error")
Error("internal-error", ErrorResult, "Internal server error")
Error("invalid-token", ErrorResult, "Invalid User token")
Error("invalid-scopes", ErrorResult, "Invalid User scope")

Method("Get", func() {
Description("Find user's rating for a resource")
Security(types.JWTAuth, func() {
Scope("rating:read")
})
Payload(func() {
Attribute("id", UInt, "ID of a resource")
Token("token", String, "JWT")
Required("id", "token")
})
Result(func() {
Attribute("rating", Int, "User rating for resource", func() {
Example("rating", 4)
})
Required("rating")
})

HTTP(func() {
GET("/resource/{id}/rating")
Cookie("token:Authorization")

Response("not-found", StatusNotFound)
Response("internal-error", StatusInternalServerError)
Response("invalid-token", StatusUnauthorized)
Response("invalid-scopes", StatusForbidden)
})
})
})
```

On running the `goa-gen` command it gets executed correctly
but on running the api it gives the following error

```
# github.com/tektoncd/hub/api/gen/http/rating/server
gen/http/rating/server/encode_decode.go:41:4: token redeclared in this block
previous declaration at gen/http/rating/server/encode_decode.go:40:4
gen/http/rating/server/types.go:295:43: duplicate argument token
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.