Azure应用程序自定义身份验证签名密钥

本文关键字:密钥 身份验证 应用程序 自定义 Azure | 更新日期: 2023-09-27 18:07:45

我正在关注以下文档:https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-backend-how-to-use-server-sdk/以建立自定义身份验证。我想知道以下代码片段中的SginingKey格式是什么:

app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions()
{
    // Here
    SigningKey = ConfigurationManager.AppSettings["authSigningKey"],
    ValidAudiences = new[] { ConfigurationManager.AppSettings["authAudience"] },
    ValidIssuers = new[] { ConfigurationManager.AppSettings["authIssuer"] },
    TokenHandler = config.GetAppServiceTokenHandler()
});

和:

JwtSecurityToken token = AppServiceLoginHandler.CreateToken(
new Claim[] { new 
Claim(JwtRegisteredClaimNames.Sub, assertion["username"]) },
                // And here
                mySigningKey,
                myAppURL,
                myAppURL,
                TimeSpan.FromHours(24));

它是Base64String吗?正常字符串?我注意到在一些零散的例子中,它有时是一个转换为Base64String的字节数组。

什么是正确的字符串格式?如何生成测试值

Azure应用程序自定义身份验证签名密钥

签名密钥是一个十六进制编码的字符串。您可以将任何值用于测试目的,前提是用于生成JWT令牌的密钥与用于验证它们的密钥相同。

您可以通过打开浏览器来检索Azure Web或移动应用程序中使用的值https://your_app_name.scm.azurewebsites.net/Env.cshtml#envVariables以及查找WEBSITE_AUTH_SIGNING_KEY值。

这是您用来对密钥进行签名的任何东西。如果您正在指定一个Base64字符串(这是正常的(,那么就是这样。请注意,UseAppServiceAuthentication部分仅在本地运行服务时使用。在Azure应用程序服务中运行时,它会自动为您处理。