gpt4 book ai didi

firebase - Go SDK 上的 VerifyIDToken panic

转载 作者:行者123 更新时间:2023-12-01 22:25:03 25 4
gpt4 key购买 nike

我不知道为什么 Go SDK 上的 VerifyIDToken 会 panic 。我在 gin 的处理程序上使用了 VerifyIDToken,如下所示:

    r.GET("/idToken/:id", func(c *gin.Context) {
// idToken := c.Param("id")
opt := option.WithCredentialsFile("xxx-secret.json")
app, err := firebase.NewApp(context.Background(), nil, opt)
if err != nil {
fmt.Println(fmt.Errorf("error initializing app: %v", err))
}

client, err := app.Auth(context.Background())
if err != nil {
fmt.Println("error getting Auth client: %v\n", err)
fmt.Println(client)
}

idToken := c.Param("id")
fmt.Println("idTaken = ", idToken)

token, err := client.VerifyIDToken(context.Background(), idToken)
if err != nil {
fmt.Println("error verifying ID token: %v\n", err)
}
fmt.Println("Verified ID token: %v\n", token)
})

我已经按如下方式调用了上面的 API:
    firebase.auth().onAuthStateChanged(function(user) {
if (user) {

user.getIdToken(/* forceRefresh */ true).then(function(idToken) {
// Send token to your backend via HTTPS
// ...
axios
.get('https://xx.xxx.com/idToken/' + idToken)
.then(response => {
this.response = response;
console.log(response);
if (response.data.update == "ok") {
this.acceptOKresponse = true;
}
})
}).catch(function(error) {
// Handle error
});

然后,服务器控制台上出现了以下内容:
idTaken =  eyJhbGciOiJSUzI1NiIsImtpZCI6IjBlYTNmN2EwMjQ4YmU0ZTBkZjAyYWVlZWIyMGIxZDJlMmI3ZjI0NzQiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoi5LiK55Sw5YGl5LmLIiwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL21hZ2ljbGFiZWwtYjQ0NjkiLCJhdWQiOiJtYWdpY2xhYmVsLWI0NDY5IiwiYXV0aF90aW1lIjoxNTgzMTE2MjQwLCJ1c2VyX2lkIjoiS0V5b3dYZnd4NFNqbEMwakdsTnVzcDU0c0xQMiIsInN1YiI6IktFeW93WGZ3eDRTamxDMGpHbE51c3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W1haWwiOiJnZGUwMDEwN0BuaWZ0eS5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJnZGUwMDEwN0BuaWZ0eS5jb20iXX0sInNpZ25faW5fcHJvdmlkZXIiOiJwYXNzd29yZCJ9fQ.ABnMA6iOITghzo_WzgdDwssODiLsswVSlKod6w5CHcnkJOQVKqQIynZufTQvcF8nQO77MYXikZD8TQE_uGq3EpHWQibun67mvN74GnPaguzgvpjQ-PqIOzuhnn2n2SpHSacdREtFkwtj1S66bhigbuTJbqr8jQtIEIB6gfmnObwcmpNRsc-GGR45xjWAO6UY4Ygw4xDcHsHGXwL6SA-HbDuSZGeQfXtdPt94taJfrQQB9nr_7gRjttQLz4ongh-g-fMSpWx3z8lmQgPwgg4GyChYPZ6_hdEV3AWFJTHptE2X8RCV6HfpZB6EGwvLQr6ZrC01uodGTg87BvtPrersjA HTTP/1.1
Host: ml.uedasoft.com
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: ja,en;q=0.9,fr;q=0.8,en-US;q=0.7
Connection: Keep-Alive
Origin: http://localhost:8080
Referer: http://localhost:8080/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36
X-Forwarded-For: 125.172.88.148
X-Forwarded-Host: ml.uedasoft.com
X-Forwarded-Server: ml.uedasoft.com


runtime error: invalid memory address or nil pointer dereference
/usr/local/go/src/runtime/panic.go:199 (0x5595f)
panicmem: panic(memoryError)
/usr/local/go/src/runtime/signal_unix.go:394 (0x55838)
sigpanic: panicmem()
/usr/local/go/src/runtime/internal/atomic/atomic_arm.go:103 (0x126db)
goXadd64: *(*int)(nil) = 0 // crash on unaligned uint64
/home/ueda/.go/src/go.opencensus.io/trace/trace.go:483 (0x50b937)
(*defaultIDGenerator).NewSpanID: id = atomic.AddUint64(&gen.nextSpanID, gen.spanIDInc)
/home/ueda/.go/src/go.opencensus.io/trace/trace.go:196 (0x50a26f)
startSpanInternal: span.spanContext.SpanID = cfg.IDGenerator.NewSpanID()
/home/ueda/.go/src/go.opencensus.io/trace/trace.go:162 (0x50a117)
StartSpan: span := startSpanInternal(name, parent != SpanContext{}, parent, false, opts)
/home/ueda/.go/src/go.opencensus.io/plugin/ochttp/trace.go:58 (0x51713b)
(*traceTransport).RoundTrip: ctx, span := trace.StartSpan(req.Context(), name,
/home/ueda/.go/src/go.opencensus.io/plugin/ochttp/client_stats.go:54 (0x516b1b)
statsTransport.RoundTrip: resp, err := t.base.RoundTrip(req)
/home/ueda/.go/src/go.opencensus.io/plugin/ochttp/client.go:89 (0x5165c7)
(*Transport).RoundTrip: return rt.RoundTrip(req)
/usr/local/go/src/net/http/client.go:250 (0x25ec27)
send: resp, err = rt.RoundTrip(req)
/usr/local/go/src/net/http/client.go:174 (0x25e6ef)
(*Client).send: resp, didTimeout, err = send(req, c.transport(), deadline)
/usr/local/go/src/net/http/client.go:641 (0x25fb17)
(*Client).do: if resp, didTimeout, err = c.send(req, deadline); err != nil {
/usr/local/go/src/net/http/client.go:509 (0x4f9def)
(*Client).Do: return c.do(req)
/home/ueda/.go/src/golang.org/x/net/context/ctxhttp/ctxhttp.go:30 (0x4f9d60)
Do: resp, err := client.Do(req.WithContext(ctx))
/home/ueda/.go/src/firebase.google.com/go/auth/token_verifier.go:92 (0x59750b)
(*httpKeySource).refreshKeys: resp, err := ctxhttp.Do(ctx, k.HTTPClient, req)
/home/ueda/.go/src/firebase.google.com/go/auth/token_verifier.go:72 (0x59733b)
(*httpKeySource).Keys: err := k.refreshKeys(ctx)
/home/ueda/.go/src/firebase.google.com/go/auth/token_verifier.go:129 (0x5979e3)
verifyToken: keys, err := ks.Keys(ctx)
/home/ueda/.go/src/firebase.google.com/go/auth/auth.go:223 (0x59529f)
(*Client).VerifyIDToken: if err := verifyToken(ctx, idToken, c.keySource); err != nil {
/home/ueda/ml/main.go:97 (0x5fdc33)
main.func5: token, err := client.VerifyIDToken(context.Background(), idToken)
/home/ueda/.go/src/github.com/gin-gonic/gin/context.go:147 (0x48710f)
(*Context).Next: c.handlers[c.index](c)
/home/ueda/.go/src/github.com/gin-gonic/gin/recovery.go:83 (0x497efb)
RecoveryWithWriter.func1: c.Next()
/home/ueda/.go/src/github.com/gin-gonic/gin/context.go:147 (0x48710f)
(*Context).Next: c.handlers[c.index](c)
/home/ueda/.go/src/github.com/gin-gonic/gin/logger.go:241 (0x497347)
LoggerWithConfig.func1: c.Next()
/home/ueda/.go/src/github.com/gin-gonic/gin/context.go:147 (0x48710f)
(*Context).Next: c.handlers[c.index](c)
/home/ueda/.go/src/github.com/gin-gonic/gin/gin.go:412 (0x48f8bf)
(*Engine).handleHTTPRequest: c.Next()
/home/ueda/.go/src/github.com/gin-gonic/gin/gin.go:370 (0x48f19f)
(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
/usr/local/go/src/net/http/server.go:2802 (0x2a2c7f)
serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/usr/local/go/src/net/http/server.go:1890 (0x29f12f)
(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/usr/local/go/src/runtime/asm_arm.s:868 (0x6c86f)
goexit: MOVW R0, R0 // NOP

[GIN] 2020/03/02 - 13:35:58 | 500 | 13.345389ms | 125.172.88.148 | GET /idToken/eyJhbGciOiJSUzI1NiIsImtpZCI6IjBlYTNmN2EwMjQ4YmU0ZTBkZjAyYWVlZWIyMGIxZDJlMmI3ZjI0NzQiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoi5LiK55Sw5YGl5LmLIiwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL21hZ2ljbGFiZWwtYjQ0NjkiLCJhdWQiOiJtYWdpY2xhYmVsLWI0NDY5IiwiYXV0aF90aW1lIjoxNTgzMTE2MjQwLCJ1c2VyX2lkIjoiS0V5b3dYZnd4NFNqbEMwakdsTnVzcDU0c0xQMiIsInN1YiI6IktFeW93WGZ3eDRTamxDMGpHbE51c3A1NHNMUDIiLCJpYXQiOjE1ODMxMjM3NTcsImV4cCI6MTU4MzEyNzM1NywiZW1haWwiOiJnZGUwMDEwN0BuaWZ0eS5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJnZGUwMDEwN0BuaWZ0eS5jb20iXX0sInNpZ25faW5fcHJvdmlkZXIiOiJwYXNzd29yZCJ9fQ.ABnMA6iOITghzo_WzgdDwssODiLsswVSlKod6w5CHcnkJOQVKqQIynZufTQvcF8nQO77MYXikZD8TQE_uGq3EpHWQibun67mvN74GnPaguzgvpjQ-PqIOzuhnn2n2SpHSacdREtFkwtj1S66bhigbuTJbqr8jQtIEIB6gfmnObwcmpNRsc-GGR45xjWAO6UY4Ygw4xDcHsHGXwL6SA-HbDuSZGeQfXtdPt94taJfrQQB9nr_7gRjttQLz4ongh-g-fMSpWx3z8lmQgPwgg4GyChYPZ6_hdEV3AWFJTHptE2X8RCV6HfpZB6EGwvLQr6ZrC01uodGTg87BvtPrersjA

我完全不知道这种 panic 的原因。任何建议都非常受欢迎!谢谢你的建议。

最佳答案

commentedmkopriva ,根本原因是报告的问题。通过更新依赖项来修复它,如下所示:

go get -u all

谢谢你,mkopriva!

关于firebase - Go SDK 上的 VerifyIDToken panic ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60482703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com