「単なるメモだ。今どきのASP.NETではユーザー管理機能を自動生成できる。自前で管理したIDパスワードも使用できるほか、OAuthでGoogleのIDでもログインできる優れものだ」
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OAuth;
using Owin;
using WebRole1.Providers;
using WebRole1.Util;
namespace WebRole1
{
public partial class Startup
{
static Startup()
{
PublicClientId = "self";
//UserManagerFactory = () => new UserManager<IdentityUser>(new MyCloudUserStore());
//OAuthOptions = new OAuthAuthorizationServerOptions
//{
// TokenEndpointPath = new PathString("/Token"),
// Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
// AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
// AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
// AllowInsecureHttp = true
//};
}
public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; }
public static Func<UserManager<IdentityUser>> UserManagerFactory { get; set; }
public static string PublicClientId { get; private set; }
//認証設定の詳細については、http://go.microsoft.com/fwlink/?LinkId=301864 を参照してください
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account2/Login")
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// アプリケーションがベアラ トークンを使用してユーザーを認証できるようにします
//app.UseOAuthBearerTokens(OAuthOptions);
// 次の行のコメントを解除して、サード パーティのログイン プロバイダーを使用したログインを有効にします
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication();
}
}
}