Setup
- I m following the docs here.
- I m using Next.js middleware which means I cannot use Firebase functions to verify my cookie. So, I m attempting to verify it with jose.
- The Firebase docs state
确保本届会议的表象由与象征性的 s夫索赔相应的私人钥匙签署。 查阅,并利用JWT图书馆核实签名。
What I ve tried
// middleware.js
import { NextResponse } from next/server
import * as jose from jose
export async function middleware(request) {
// Check the cookies
const allCookies = request.cookies.getAll()
console.log(allCookies)
// Get the sessionCookie (if it exists)
const sessionCookie = request.cookies.get("sessionCookie")
console.log("sessionCookie", sessionCookie)
// Test verification using a hard-coded public key from
// https://www.googleapis.com/identitytoolkit/v3/relyingparty/publicKeys
const alg = RS256
const spki = `-----BEGIN CERTIFICATE-----
MIIDHDCCAgSgAwIBAgIEIhgI5zANBgkqhkiG9w0BAQsFADAzMQ8wDQYDVQQDEwZH
aXRraXQxEzARBgNVBAoTCkdvb2dsZSBJbmMxCzAJBgNVBAYTAlVTMB4XDTE5MDEx
NDIzMjgzMVoXDTIwMDEwOTIzMjgzMVowMzEPMA0GA1UEAxMGR2l0a2l0MRMwEQYD
VQQKEwpHb29nbGUgSW5jMQswCQYDVQQGEwJVUzCCASIwDQYJKoZIhvcNAQEBBQAD
ggEPADCCAQoCggEBAMLh7U8PNsOebb1HVLDa81W/CZK8DrdYl9Vlwj/0/GF7kfLP
zF4qyShw1zAZddlzt7f6lDy2ZvmQ1nqW0IRy8xgYTeAb6aCLY+rm4DEnwJOCnAVo
m1xpgcOVExsXXpleWsP0MugM5xa91Y79CYkVTevPZThgjqfGjan3GiXLQwIJTLG8
xEXXSzmMDeW6dP6CBVPsbbTYSat6CX2nBm2YoJ4v2dij3DQBzOD/d5WLaYL4yE9p
TjmreitFvs1r0AZF53Cq5ju7M10indVyk1zwfK+tuk7VnCZz/mBHEPxT9+Q5EWFi
lVVkZ+2Qau0qRIvar/1QukVpyEsVHPZH+aZ9ilMCAwEAAaM4MDYwDAYDVR0TAQH/
BAIwADAWBgNVHSUBAf8EDDAKBggrBgEFBQcDAjAOBgNVHQ8BAf8EBAMCB4AwDQYJ
KoZIhvcNAQELBQADggEBAH4ca9fhlBd9XmaX9E0rZ8QCWT8AnxcVLY+S+nHJg2IT
dj7ZytNJWttKEssOdslrQyamxt2SdQSfpd2UpA+fCO2sRSJOBEA3squGrj1yh1Pt
lajf2TM1MwpdO7ZqBbfE3hLH7srBbVXHxKsUemepxviC+dpF0u4o3EjqHpAvkruO
4RtC4grbFBNRIbBTu7oJHpKnBJWxK7w11a5Sabs6reAuFh68QaVAQzrscYP/M4i9
SPwArWKoCJgrxxVof1N1cal4UpziEH9OaWa7RfyZTYAeEJ/atDo5s8AACPUH542f
JEwmwAJKbJKLRoFYJJXCPeKp1Q7EXQHJNNdS2ABjw+w=
-----END CERTIFICATE-----`
const publicKey = await jose.importSPKI(spki, alg)
const { payload, protectedHeader } = await jose.jwtVerify(sessionCookie.value, publicKey)
console.log(protectedHeader)
console.log(payload)
}
造成错误
“空白”必须是SPKI格式的扼制错误
Questions
我如何做这项工作?
每个公共钥匙似乎都有独特的(关键、价值)乳制品。 例如
"skIBNg": "-----BEGIN CERTIFICATE----- MIIDHDCCAgSgAwIB...vb2dsZSBJbmMxCzAJBgNVBAYTA.f+9Vg= -----END CERTIFICATE----- "
key skIBNg>
? 目前没有使用。