douke1891 2017-05-18 00:05
浏览 121

在Golang和Goa的JWT索赔中不存在范围

I am using the excellent goa package to generate my API in Go.

However, I am having an issue with its security middleware and when I submit a bearer token to my controllers, I get "authorization failed" because of "scopes:null". I am using Auth0 for authentication and it is generating the bearer token. The exact error in Postman is:

{"id":"xOUR882s","code":"jwt_security_error","status":401,"detail":"authorization failed: required 'scopes' not present in JWT claim","meta":{"required":["read:meta"],"scopes":null}}

However, my token does include the required scope read:meta. jwt.io gives back the following decoded bearer:

{
  "iss": "https://learnlogic.au.auth0.com/",
  "sub": "exJMkK7hXX56lrLwoTqna3s0jh7Gq67e@clients",
  "aud": "https://api.learn-logic.com",
  "exp": 1494855336,
  "iat": 1494768936,
  "scopes": "read:meta"
}

I am hoping someone can help me workout why, as I don't really understand what is going on in middleware/jwt.go in the goa project which may be found here. My only thought is that something about the Auth0 formatted bearer is not compatible with the parseClaimScopes function in middleware/jwt.go, but I don't know what.

I have the following main.go code:

b, err := ioutil.ReadFile("util/jwt.key")
    if err != nil {
        return
    }

    block, _ := pem.Decode([]byte(b))
    var cert *x509.Certificate
    cert, _ = x509.ParseCertificate(block.Bytes)
    rsaPublicKey := cert.PublicKey.(*rsa.PublicKey)
    fmt.Println(rsaPublicKey.N)
    fmt.Println(rsaPublicKey.E)
    fmt.Println(cert)

    var keyx = []jwt.Key{rsaPublicKey}

    var jwtResolver = jwt.NewSimpleResolver(keyx)

    app.UseJWTMiddleware(service, jwt.New(jwtResolver, nil, app.NewJWTSecurity()))

The certificate I am reading in is the same one used in jwt.io to decode the bearer token.

Any help is much appreciated.

  • 写回答

1条回答 默认 最新

  • douhan4093 2019-03-18 22:08
    关注

    According to this ticket https://github.com/goadesign/goa/issues/1228, the problem was due to the fact there was only a support for a claim with a singular name "scope" and not the plural "scopes". This PR https://github.com/goadesign/goa/pull/1399, added the plural version.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度