简体   繁体   English

Azure 应用服务身份验证 - SQL 数据库客户端分片

[英]Azure App service authentication - SQL database client sharding

We have an azure SQL database that will contain multiple client's data.我们有一个包含多个客户数据的 azure SQL 数据库。 Each table has an account Id which we were planning on using use to seperate client data.每个表都有一个帐户 ID,我们计划用它来分离客户数据。 We are displaying the data via an Azure App service and an bff middleware in azure function app.我们通过 Azure 应用程序服务和 azure 函数应用程序中的 bff 中间件显示数据。 We were planning on adding Azure App Service Authentication to authenticate users into our web app.我们计划添加 Azure 应用服务身份验证以在我们的 Web 应用程序中对用户进行身份验证。

However we cannot find documentation on how to store an account Id against an authenticated user;但是,我们找不到有关如何针对经过身份验证的用户存储帐户 ID 的文档; so that we could return results from the database specific only for that user/client?以便我们可以从特定于该用户/客户端的数据库中返回结果?

App Service passes user claims to your application by using special headers.应用服务使用特殊标头将用户声明传递给您的应用程序。 External requests aren't allowed to set these headers, so they are present only if set by App Service.不允许外部请求设置这些标头,因此它们仅在由应用服务设置时才存在。

There are two ways to get the usename(Account id to login).有两种方法可以获取用户名(要登录的帐户 ID)。
1.You could use X-MS-CLIENT-PRINCIPAL-NAME as http resquest header to get the username. 1.您可以使用X-MS-CLIENT-PRINCIPAL-NAME作为 http 请求头来获取用户名。

var name1=httpRequest.Headers["X-MS-CLIENT-PRINCIPAL-NAME"].ToString();

2.You can retrieve the authenticated user information from the ClaimsPrincipal instance injected in the Run method. 2.您可以从 Run 方法中注入的 ClaimsPrincipal 实例中检索经过身份验证的用户信息。

public static async Task<HttpResponseMessage> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]
    HttpRequest httpRequest, 
    ILogger logger, 
    ClaimsPrincipal claimsPrincipal)
{   
    var name2 = claimsPrincipal.Identity.Name;
}

After get the username(Account id to login), you can add it to the conditions of the sql statement.获取到用户名(要登录的帐号)后,可以将其添加到sql语句的条件中。

Note:笔记:

When you add App registrations in Azure ad, add redirect url as https://yourfunctionname.azurewebsites.net/.auth/login/aad/callback and click ID token when you setting Advanced settings .在 Azure 广告中添加应用程序注册时,将重定向 url添加为https://yourfunctionname.azurewebsites.net/.auth/login/aad/callback并在设置Advanced settings时单击ID token

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM