Golang 和果阿的 JWT 声明中不存在范围

Ben*_*Ben 5 go jwt auth0

我正在使用优秀的goa包在 Go 中生成我的 API。

但是,我的安全中间件存在问题,当我向控制器提交不记名令牌时,由于“scopes:null”,我收到“授权失败”。我使用 Auth0 进行身份验证,它正在生成不记名令牌。Postman 中的确切错误是:

{"id":"xOUR882s","code":"jwt_security_error","status":401,"detail":"authorization failed: required 'scopes' not present in JWT claim","meta":{"required":["read:meta"],"scopes":null}}
Run Code Online (Sandbox Code Playgroud)

但是,我的令牌确实包含所需的范围read:metajwt.io返回以下解码后的承载:

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

middleware/jwt.go我希望有人可以帮助我解决原因,因为我真的不明白该项目中发生了什么goa,可以在这里找到。我唯一的想法是 Auth0 格式的承载的某些内容与parseClaimScopes中的功能不兼容middleware/jwt.go,但我不知道是什么。

我有以下main.go代码:

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()))
Run Code Online (Sandbox Code Playgroud)

我正在读取的证书与jwt.io中用于解码不记名令牌的证书相同。

任何帮助深表感谢。

ant*_*ham 0

根据此票证https://github.com/goadesign/goa/issues/1228,问题是由于仅支持单数名称“scope”而不是复数“scopes”的声明。此 PR https://github.com/goadesign/goa/pull/1399,添加了复数版本。