Azure移动应用程序没有应用程序密钥-什么';这是一个简单的替代品吗?
我一直在使用Azure移动服务,现在我通过全新的Azure门户创建了一个新的移动应用程序 在使用移动服务时,可以通过应用程序密钥限制API访问。这个密钥的概念似乎不再适用于移动应用程序 我所需要的只是对我的服务进行真正的轻量级保护,这正是应用程序密钥所做的。我只是想防止所有人都导航到我的Azure应用程序,并干扰我的数据库;当你没有任何东西要隐藏,但想防止“垃圾邮件”时,应用程序密钥非常适合这些情况 我看到现在有Active Directory集成作为替代方案,但不幸的是,我找不到如何从应用程序密钥移动到其他应用程序的指南。查看此帖子 此验证示例代码适用于UWPAzure移动应用程序没有应用程序密钥-什么';这是一个简单的替代品吗?,azure,azure-mobile-services,Azure,Azure Mobile Services,我一直在使用Azure移动服务,现在我通过全新的Azure门户创建了一个新的移动应用程序 在使用移动服务时,可以通过应用程序密钥限制API访问。这个密钥的概念似乎不再适用于移动应用程序 我所需要的只是对我的服务进行真正的轻量级保护,这正是应用程序密钥所做的。我只是想防止所有人都导航到我的Azure应用程序,并干扰我的数据库;当你没有任何东西要隐藏,但想防止“垃圾邮件”时,应用程序密钥非常适合这些情况 我看到现在有Active Directory集成作为替代方案,但不幸的是,我找不到如何从应用程序
private async Task AuthenticateAsync()
{
while (user == null)
{
string message=string.Empty;
var provider = "AAD";
PasswordVault vault=new PasswordVault();
PasswordCredential credential = null;
try
{
credential = vault.FindAllByResource(provider).FirstOrDefault();
}
catch (Exception)
{
//Ignore exception
}
if (credential != null)
{
// Create user
user = new MobileServiceUser(credential.UserName);
credential.RetrievePassword();
user.MobileServiceAuthenticationToken = credential.Password;
// Add user
App.MobileServiceClient.CurrentUser = user;
try
{
//intentamos obtener un elemento para determinar si nuestro cache ha experidado
await App.MobileServiceClient.GetTable<Person>().Take(1).ToListAsync();
}
catch (MobileServiceInvalidOperationException ex)
{
if (ex.Response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
//remove expired token
vault.Remove(credential);
credential = null;
continue;
}
}
}
else
{
try
{
//Login
user = await App.MobileServiceClient
.LoginAsync(provider);
//Create and store credentials
credential = new PasswordCredential(provider,
user.UserId, user.MobileServiceAuthenticationToken);
vault.Add(credential);
}
catch (MobileServiceInvalidOperationException ex)
{
message = "You must log in. Login Required";
}
}
message = string.Format("You are now logged in - {0}", user.UserId);
var dialog = new MessageDialog(message);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}
private异步任务AuthenticateAsync()
{
while(user==null)
{
字符串消息=string.Empty;
var provider=“AAD”;
PasswordVault=新的PasswordVault();
PasswordCredential-credential=null;
尝试
{
凭证=vault.FindAllByResource(提供程序).FirstOrDefault();
}
捕获(例外)
{
//忽略异常
}
如果(凭证!=null)
{
//创建用户
用户=新的MobileServiceUser(凭证.用户名);
credential.RetrievePassword();
user.MobileServiceAuthenticationToken=凭证.Password;
//添加用户
App.MobileServiceClient.CurrentUser=用户;
尝试
{
//获取数据的目的是为数据缓存提供数据
等待App.MobileServiceClient.GetTable().Take(1.toListSync();
}
捕获(MobileServiceInvalidOperationException ex)
{
if(ex.Response.StatusCode==System.Net.HttpStatusCode.Unauthorized)
{
//删除过期令牌
删除(凭证);
凭证=null;
继续;
}
}
}
其他的
{
尝试
{
//登录
user=wait App.MobileServiceClient
.LoginAsync(提供商);
//创建和存储凭据
凭证=新密码凭证(提供程序,
user.UserId、user.MobileServiceAuthenticationToken);
添加(凭证);
}
捕获(MobileServiceInvalidOperationException ex)
{
message=“您必须登录,需要登录”;
}
}
message=string.Format(“您现在登录到-{0}”,user.UserId);
var dialog=新建消息对话框(消息);
添加(新的UICommand(“OK”);
wait dialog.ShowAsync();
}
}
查看此帖子
此验证示例代码适用于UWP
private async Task AuthenticateAsync()
{
while (user == null)
{
string message=string.Empty;
var provider = "AAD";
PasswordVault vault=new PasswordVault();
PasswordCredential credential = null;
try
{
credential = vault.FindAllByResource(provider).FirstOrDefault();
}
catch (Exception)
{
//Ignore exception
}
if (credential != null)
{
// Create user
user = new MobileServiceUser(credential.UserName);
credential.RetrievePassword();
user.MobileServiceAuthenticationToken = credential.Password;
// Add user
App.MobileServiceClient.CurrentUser = user;
try
{
//intentamos obtener un elemento para determinar si nuestro cache ha experidado
await App.MobileServiceClient.GetTable<Person>().Take(1).ToListAsync();
}
catch (MobileServiceInvalidOperationException ex)
{
if (ex.Response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
//remove expired token
vault.Remove(credential);
credential = null;
continue;
}
}
}
else
{
try
{
//Login
user = await App.MobileServiceClient
.LoginAsync(provider);
//Create and store credentials
credential = new PasswordCredential(provider,
user.UserId, user.MobileServiceAuthenticationToken);
vault.Add(credential);
}
catch (MobileServiceInvalidOperationException ex)
{
message = "You must log in. Login Required";
}
}
message = string.Format("You are now logged in - {0}", user.UserId);
var dialog = new MessageDialog(message);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}
private异步任务AuthenticateAsync()
{
while(user==null)
{
字符串消息=string.Empty;
var provider=“AAD”;
PasswordVault=新的PasswordVault();
PasswordCredential-credential=null;
尝试
{
凭证=vault.FindAllByResource(提供程序).FirstOrDefault();
}
捕获(例外)
{
//忽略异常
}
如果(凭证!=null)
{
//创建用户
用户=新的MobileServiceUser(凭证.用户名);
credential.RetrievePassword();
user.MobileServiceAuthenticationToken=凭证.Password;
//添加用户
App.MobileServiceClient.CurrentUser=用户;
尝试
{
//获取数据的目的是为数据缓存提供数据
等待App.MobileServiceClient.GetTable().Take(1.toListSync();
}
捕获(MobileServiceInvalidOperationException ex)
{
if(ex.Response.StatusCode==System.Net.HttpStatusCode.Unauthorized)
{
//删除过期令牌
删除(凭证);
凭证=null;
继续;
}
}
}
其他的
{
尝试
{
//登录
user=wait App.MobileServiceClient
.LoginAsync(提供商);
//创建和存储凭据
凭证=新密码凭证(提供程序,
user.UserId、user.MobileServiceAuthenticationToken);
添加(凭证);
}
捕获(MobileServiceInvalidOperationException ex)
{
message=“您必须登录,需要登录”;
}
}
message=string.Format(“您现在登录到-{0}”,user.UserId);
var dialog=新建消息对话框(消息);
添加(新的UICommand(“OK”);
wait dialog.ShowAsync();
}
}
Azure移动服务[此处]解决了应用程序关键问题。[此处]:Azure移动服务解决了应用程序关键问题[此处]。[这里]: