【发布时间】:2015-10-06 17:44:53
【问题描述】:
我已经使用 Azure 移动服务和我的 Windows Phone 8.1 应用成功设置了自定义身份验证过程(按照指南 here)
我现在正在创建一个 MVC5 单页应用程序 (SPA) 来管理系统的管理方面。我对 MVC5 比较陌生,只需要一点帮助就可以开始执行登录,就像在我的手机应用中一样?
目前我的手机应用通过以下方式登录
App.MobileService.CurrentUser = await AuthenticateAsync(this.textBox_email.Text, textBox_password.Password);
会的
private async Task<MobileServiceUser> AuthenticateAsync(string username, string password)
{
// Call the CustomLogin API and set the returned MobileServiceUser
// as the current user.
var user = await App.MobileService
.InvokeApiAsync<LoginRequest, MobileServiceUser>(
"CustomLogin", new LoginRequest()
{
UserName = username,
Password = password
});
return user;
}
这一切都很好,所以我想问题是我如何在 MVC5 中以相同的方式调用我的客户身份验证 API 并在成功时设置用户上下文?
Startup.Auth.cs:
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication();
}
如果我缺少任何信息或细节,请告诉我。 谢谢!
【问题讨论】:
标签: asp.net-mvc-5 azure-mobile-services