Previously I'm using Azure Mobile App as our Mobile Application backend and now my company ask me to develop Website interface and all our current user should be able to login with existing account.
I'm using Adrian method as my base (link to guide)
Everything work fine. The Mobile App and Website is under the same App service. Except the website generate different userID compare to the mobile app when authenticated (in my case Facebook & Google)
Website User
{azure-URL}/.auth/login/facebook
UserID : xxx
<div class="panel-body">
<a href="/.auth/login/facebook?post_login_redirect_url=/Home" class="btn btn-block btn-social btn-facebook">
<i class="fa fa-facebook"></i> Sign in with Facebook
</a>
</div>
Mobile User
Using LoginAsync() Or calling {azure-URL}/.auth/login/facebook
UserID : sid:xxx
This is my Startup.cs
public static void ConfigureMobileApp(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
new MobileAppConfiguration()
.AddTables(
new MobileAppTableConfiguration()
.MapTableControllers()
.AddEntityFramework())
.MapApiControllers()
.AddPushNotifications()
.ApplyTo(config);
// Use Entity Framework Code First to create database tables based on your DbContext
// Database.SetInitializer(new MobileServiceInitializer());
var migrator = new DbMigrator(new Migrations.Configuration());
migrator.Update();
MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnApplyRedirect = ctx =>
{
if (!IsZumoAuth(ctx.Request))
{
ctx.Response.Redirect(ctx.RedirectUri);
}
}
}
});
if (string.IsNullOrEmpty(settings.HostName))
{
app.Use(typeof(CustomAppServiceAuthenticationMiddleware), app, new AppServiceAuthenticationOptions
//app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
{
// This middleware is intended to be used locally for debugging. By default, HostName will
// only have a value when running in an App Service application.
SigningKey = ConfigurationManager.AppSettings["SigningKey"],
ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
TokenHandler = config.GetAppServiceTokenHandler()
});
}
app.UseWebApi(config);
}
Is there anything I miss?