简体   繁体   English

如何保护 Xamarin Forms 中 MobileServiceClient 的 Azure App Service 端点?

[英]How do I secure Azure App Service end-point for MobileServiceClient in Xamarin Forms?

I have an app that uses Auth0 https://auth0.com/ as the login provider and can login through multiple providers - Facebook, LinkedIn, Google, MS and Apple.我有一个应用程序使用Auth0 https://auth0.com/作为登录提供商,可以通过多个提供商登录 - Facebook、LinkedIn、Google、MS 和 Apple。 This all happens client-side and I get the id and access tokens from the relevant service.这一切都发生在客户端,我从相关服务获取 ID 和访问令牌。 No errors.没有错误。

My app then connects to Azure App Services using the Microsoft.WindowsAzure.MobileServices API I use this to create the connection to the service:然后我的应用程序使用 Microsoft.WindowsAzure.MobileServices API 连接到 Azure App Services 我用它来创建与服务的连接:

client = new MobileServiceClient(https://mycompany.azurewebsites.net);

The app can then sync data between the local SQLite db and my Azure SQL db.然后应用程序可以在本地 SQLite db 和我的 Azure SQL db 之间同步数据。 This all WORKS, no errors.这一切都有效,没有错误。

PROBLEM - the endpoint https://mycompany.azurewebsites.net is set with anonymous access and is not secured.问题 - 端点https://mycompany.azurewebsites.net设置为匿名访问且不安全。

I can enable App Service Authentication and implement something like this for most authentication services, passing in the already-received tokens from login:我可以启用 App Service Authentication 并为大多数身份验证服务实现类似的功能,从登录中传入已收到的令牌:

task = Task.Run(async () => await client.LoginAsync(MobileServiceAuthenticationProvider.Facebook, AccessToken));
user = task.Result;

This is fine for MS, Facebook and Google authentication BUT there is nothing in the API for LinkedIn or Apple.这适用于 MS、Facebook 和 Google 身份验证,但 LinkedIn 或 Apple 的 API 中没有任何内容。

Apple certification requires and Apple login IF other provider login choices are also made available to the user. Apple 认证需要 Apple 登录,如果其他供应商登录选项也可供用户使用。

Question: How can I secure the Azure App Service in Node.js to accept an app ID and or password or token that I can supply from the client side as a constant to simply allow generic but somewhat secure access to this URL: https://mycompany.azurewebsites.net and NOT have this set with anonymous access?问题:我如何保护 Node.js 中的 Azure 应用服务,以接受我可以从客户端提供的应用 ID 和/或密码或令牌作为常量,以简单地允许对此 URL 进行通用但有点安全的访问: https://mycompany .azurewebsites.net并且没有设置匿名访问? And NOT USE the limited App Service Authentication.并且不使用有限的应用服务身份验证。

Can anyone please shed light on this?任何人都可以阐明这一点吗? This is a major block in final progress with the app.这是应用程序最终进展的主要障碍。

I did come across this but need something Node.js AND Azure App Service specific.我确实遇到过这个,但需要特定于 Node.js 和 Azure App Service 的东西。 Azure Mobile Services, HttpClient, Authorization Azure 移动服务,HttpClient,授权

Thank you谢谢

This should easily be doable.这应该很容易做到。

  1. Update your service side so that it implements the authentication mechanism you need.更新您的服务端,以便它实现您需要的身份验证机制。
  2. Create a DelegatingHandler that implements the authentication mechanism.创建一个实现身份验证机制的 DelegatingHandler。
  3. Re-do your connection creator as follows:重新做你的连接创建者如下:
var client = new MobileServiceClient(url, new MyDelegatingHandler());

A delegating handler might be as simple as this:委托处理程序可能像这样简单:

public class MyDelegatingHandler : DelegatingHandler
{
  protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken token)
  {
    request.Headers.Add("X-Api-Key", "MyApiKey");
    return base.SendAsync(request, token);
  }
}

This just adds a header to every single request with the API key, which you would then check on the server side.这只是使用 API 密钥向每个请求添加 header,然后您将在服务器端检查它。 For Apple / LinkedIn / others, you might want to integrate those directly using an Authorization header in this way.对于 Apple / LinkedIn / 其他,您可能希望以这种方式直接使用授权 header 来集成它们。 Basically, you store the authorization header "somewhere" in your client-side code, after having done the auth, then you use a delegating handler to add the authorization header. On the server side, you can validate that authorization header in the normal way for an ASP.NET or Express app.基本上,您将授权 header 存储在客户端代码的“某处”,完成身份验证后,然后使用委托处理程序添加授权 header。在服务器端,您可以以正常方式验证该授权 header对于 ASP.NET 或 Express 应用程序。

暂无
暂无

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

相关问题 生成具有快速端点的子进程 - Spawning child process with express end-point IBM IoT到Websockets端点的输出节点 - IBM IoT output node to websockets end-point 如何在Azure App Service Linux上从Node.Js应用运行获取日志输出? - How do i get log output from Node.Js app runnng on Azure App Service Linux? 当日志不包含错误消息时,如何对 Azure Linux 应用服务进行故障排除 - How do I troubleshoot Azure Linux App Service when logs are not including error messages 我可以在Azure App Service上运行Node / ExpressJS应用程序,还是必须使用Azure Cloud Service? - Can I run a Node/ExpressJS application on Azure App Service or do I have to use Azure Cloud Service? express js api端点不适用于azure Web应用程序 - express js api end point does not work on azure web app 如何让我的 Next.js 应用在运行 ubuntu-latest 的 Azure 应用服务中启动? - How do I get my Next.js app to start in an Azure App Service running ubuntu-latest? 您如何在 Azure 应用服务中托管 Strapi? - How do you host Strapi within an Azure App Service? Azure 应用服务 - 节点应用 - 我需要创建服务器和所需文件吗 - Azure App Service - Node App - Do i need to createServer and required files http-proxy-middleware + express + node.js - 无法重定向到启用客户端证书身份验证的端点 - http-proxy-middleware + express + node.js - unable to redirect to end-point with client side certificate authentication enabled
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM