我有多个Firebase数据库,我想创建一个连接到所有数据库的管理员.要初始化应用程序,我首先需要Firebase-admin模块并初始化应用程序.如果我使用不同的凭据再次运行它,它仍然只会初始化一个应用程序.
var admin = require("firebase-admin");
...
Object.keys(config).map(function (k, i){
var c = config[k];
var serviceAccount = require(c.credential);
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
apiKey: c.apiKey,
authDomain: c.authDomain,
databaseURL: c.databaseURL,
storageBucket: c.storageBucket
}, c.name);
...
}
Run Code Online (Sandbox Code Playgroud)
这不起作用!即使有两种配置,也只会初始化一个应用程序.
我在验证 JWT 签名时遇到一个非常奇怪的错误,这在本地运行 Web 应用程序时工作正常,但是当部署到服务器时,我收到此错误:
"消息:IDX10503:签名验证失败。尝试的密钥:'System.IdentityModel.Tokens.InMemorySymmetricSecurityKey\r\n'。\n捕获的异常:\n ''。\n令牌:'{\"typ\":\"JWT\ ",\"alg\":\"HS256\"}.....
我像这样创建我的令牌
var securityKey = Encoding.UTF8.GetBytes(secret);
var tokenHandler = new JwtSecurityTokenHandler();
// Token Creation
var now = DateTime.UtcNow;
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = identity,
TokenIssuerName = "self",
AppliesToAddress = "http://example.com",
Lifetime = new Lifetime(now, now.AddMinutes(2)),
SigningCredentials = new SigningCredentials(
new InMemorySymmetricSecurityKey(securityKey),
"http://www.w3.org/2001/04/xmldsig-more#hmac-sha256",
"http://www.w3.org/2001/04/xmlenc#sha256"),
};
var token = tokenHandler.CreateToken(tokenDescriptor);
return tokenHandler.WriteToken(token);
Run Code Online (Sandbox Code Playgroud)
并像这样验证:
// Create token validation parameters for the signed JWT
// This object will be used to verify the cryptographic …Run Code Online (Sandbox Code Playgroud)