How do you specify the JWT scope for a single rout...
# sst
r
How do you specify the JWT scope for a single route?
If my claims look like this:
Copy code
{
  "sub": "5B22A526-C5C5-4D02-ADBC-95709E2CAE22",
  "cognito:groups": [
    "test"
  ],
  "event_id": "EE18407B-3E10-4E95-A549-EA93BE094687",
  "token_use": "access"
}
How can I secure the route so that a user must have cognito:groups === “test”
Can I set authorizationScopes on a route level?
f
I’m not too familiar with JWT. You are trying to assign different scopes to different routes so some routes are accessible for some users while others are not. Is that right?
r
Yeah
Basically I was to say this route requires this scope
I can do the check in the lambda code, but it would be nice if I could do it in the route defintion
Copy code
"GET /private": {
          function: "src/private.main",
          authorizationType: sst.ApiAuthorizationType.JWT,
          authorizationScopes: ["cognito:groups == test"]
        },
I thought something like this, but I am not sure if this will work, the docs are not to clear
f
Not right now.. but let me put that in today
r
The cognito groups is coming back as an array so I’m not sure how your would check for a value in an array here
f
Yeah.. the example snippet is what I have in mind too
r
You can do defaultAuthorizationScopes: [“username”, “sub”]
These work, an objects work as well
That’s awesome @Frank thank you for being so responsive.
f
@Roger Rajaratnam Just added support for this in v0.9.15 To update
Copy code
$ npm install --save --save-exact @serverless-stack/cli@0.9.15 @serverless-stack/resources@0.9.15
You can pass in
authorizationScopes
to a route like you have suggested:
Copy code
"GET /private": {
  function: "src/private.main",
  authorizationScopes: ["user.email"]
},
Give it a try and let me know if it works for you.
r
@Frank did you manage to add the ability to check array values?
f
@Roger Rajaratnam I’m not too familiar with JWT. I know u can do this with a Lambda authorizer.. I’m not sure if you can have conditions in the scope like you suggested
["cognito:groups == test"]
If you find something, definitely let me know.. it’d be useful to add it to the doc.