小编use*_*058的帖子

使用 SymmetricSecurityKey 签署 jwt 时如何指定 child?

我正在后端验证 jwt 令牌,其中可以使用不同的密钥和算法从多个来源发出令牌。

早些时候,我只使用RsaSha256密钥进行验证,现在我正在设置接受使用 签名的令牌HmacSha256

问题是 - 在验证令牌时,我曾经查看孩子值来解析证书/安全密钥。但生成的代币HmacSha256不包含孩子值。

我目前只是检查kid == null委托IssuerSigningKeyResolver以确定应使用哪个密钥进行验证(如果为 null,则使用 Hmac 密钥,否则使用匹配的 rsa 密钥)。但只要我继续仅使用一个 Hmac 密钥进行签名,它就可以工作,如果我需要使用多个对称密钥进行签名,那么我将无法确定使用哪一个进行验证。

  • 我怎样才能将孩子包含在令牌中?
  • 如果不可能,建议使用什么方法来确定验证时使用哪个密钥?
  • 另外,我也不能 100% 确定接受此类密钥的混合是否安全,不是吗?

下面大致是我使用对称密钥的令牌生成器-

var tokenHandler = new JwtSecurityTokenHandler();

var tokenDescriptor = new SecurityTokenDescriptor
{

    Subject = new ClaimsIdentity(claims),
    Issuer = issuer,
    Audience = aud,
    Expires = expirationTime,

    SigningCredentials = new SigningCredentials(
        new SymmetricSecurityKey(symmetricKey),
        SecurityAlgorithms.HmacSha256
        )
};

var securityToken = tokenHandler.CreateToken(tokenDescriptor);
Run Code Online (Sandbox Code Playgroud)

我用于Microsoft.IdentityModel.Tokens生成和验证令牌。

c# security identity jwt

7
推荐指数
1
解决办法
3041
查看次数

尽管成功执行,Firebase 可调用函数结果在客户端始终为空

我正在尝试从 android 执行 Callable 函数。

  1. 函数执行登录控制台显示调用已接收并执行,没有任何错误。
  2. 客户端的可调用任务在函数执行后收到结果,没有异常报告。
  3. 但是,接收到的结果为空。

下面是函数代码——

const Translate = require('@google-cloud/translate');
const projectId = functions.config().firebase;

const translate = new Translate({
  projectId: projectId,
});

exports.translateMessage = functions.https.onCall((data, context) => {

  let text = data.text;
  let targetLanguage = data.target_language;
  let uid = context.auth.uid;

  console.log("incoming text: " + text)
  console.log("incoming uid: " + uid)
  console.log("incoming target: " + targetLanguage)

  //In future, check if uid or custom claim has quota
  if(!uid)
    return text;

  translate
  .translate(text, targetLanguage)
  .then(results => {
    const translation = …
Run Code Online (Sandbox Code Playgroud)

android firebase google-cloud-functions

4
推荐指数
1
解决办法
951
查看次数