question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When tokenType = jwt, scope restriction doesn't work.

See original GitHub issue

EDIT:(For anyone who fac[ed|ing] this issue.) (after talking to Vincenzo)

Here’s the problem: with so many ways to represent the scopes and not a standardized way to expose these, Express Gateway would be in trouble in doing so.

The problem we have is that Express Gateway can’t locate scopes in a JWT — because it’s location is unpredictable.

You have two ways to fix this:


Tried to restrict an apiEndpoint with scopes, and any logged user , with any role, could pass through to the proxy level. After few tries, I figured this case happens only when the tokenType is “jwt”. When commenting the tokenType with it’s props (issuer, audience,subject), the scopes restriction works perfectly.

Config references (bugged reference as reproduce steps):

apiEndpoint :

apiEndpoints:
  exampleApi:
    port: *gatewaySecurePort
    host: *gatewayHost
    paths:
      - "/example/*"
    scopes:
      - 'exampleAdmin'

pipeline :

example-api:
    apiEndpoints:
      - exampleApi
    policies:
      - oauth2:
        - action:
            jwt:
              <<: *jwtStrategy
      - rewrite:
        - condition:
            name: allOf
            conditions:
              - name: authenticated
              - name: pathmatch
                match: "/example/:route*"
          action:
            rewrite: "/:route"
      - proxy:
        - condition:
            name: authenticated
          action:
            serviceEndpoint: exampleServiceApi
            changeOrigin: true

systemConfig.accessTokens :

accessTokens:
  timeToExpiry: 7200000
  tokenType: "jwt"
  issuer: "example issuer"
  audience: "example audience"
  subject: "example subject"
  secretOrPrivateKey: "very_secret_thing_example"

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
XVincentXcommented, Aug 2, 2018

Yes — you’re experiencing exactly the same issue. I wrote you a workaround in the Gitter channel (that is — use this)

1reaction
kevinswibercommented, Jul 23, 2018

Because talking about possibilities with JWT is always confusing, I’m just going to take a moment to provide a refresher on different ways JWTs manifest in authentication/authorization.

There are actually 3 ways we could potentially use JWT in a gateway.

  1. JWT as a fancy API key
  2. JWT as an OAuth2 Access Token
  3. JWT for tokens in the OpenID Connect flows.

I think in use cases 1 and 3, we could potentially take JWTs issued by an Identity Provider, and in those cases, we’d need some indication of assigned scopes, likely via a custom claim.

For use case 2, I think we’d have to manage all of that internally. And if we’re managing it internally, we should be able to take advantage of our scope management.

I think this issue is referring to use case 2, which should not require a custom scopes claim in the JWT. Scope management should work for JWT access tokens the same exact way it works for opaque access tokens.

@naorbe Feel free to comment if I’m missing something.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Restricted Access Using Scope in JWT and Spring
Well, i have a JWT with scope definied in a claim called scp, ... tokenType=BearertokenValue=<TOKEN>; Not granted any authorities' ...
Read more >
11 JWT Token Security Best Practices | Curity
ID Tokens don't have scopes, so checking whether an Access Token has any or a concrete scope will help you differentiate them. As...
Read more >
RFC 7519: JSON Web Token (JWT)
Sub-Namespace Registration of urn:ietf:params:oauth:token-type:jwt . ... valid is context dependent and is outside the scope of this specification.
Read more >
OAuth 2.0 Token Exchange RFC 8693 - IETF Datatracker
However, that does not restrict usage of this profile to traditional OAuth clients ... The value "urn:ietf:params:oauth:token-type:jwt", which is defined in ...
Read more >
Generating Tokens for API Requests - Apple Developer
JSON Web Token (JWT) is an open standard (RFC 7519) that defines a way to ... query parameters when it checks the scope:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found