私はOWINライブラリを介してGoogleアカウントでユーザーを認証するASP.NET MVCアプリケーションを手に入れました。GmailにログインせずにOWINでASP.NET MVCアプリを認証
ユーザーは、ホストコンピュータ(顧客)のコンピュータ、公開されているコンピュータのWebアプリケーションにログインして、Webアプリケーションのデータを管理することが期待されます。
Googleログインページにリダイレクトするログインボタンがあります。ユーザーはユーザー名とパスワードを入力し、このウェブアプリケーションにリダイレクトされます。これまではOKですが、これはOWINが通常どのように動作するかです。
ユーザーがアプリをログアウトするのを忘れて、誰かがウェブアプリケーションからデータを取得する危険性があります。これはすべてのWebアプリケーションの権利のリスクです、私はそれを受け入れる必要があります。しかし、ユーザーがログアウトするのを忘れた場合、誰かがGmail、Googleドキュメント、および関連するすべてのGoogleサービスからのすべてのメールを取得するという追加のリスクがあります。
私は、OwinがユーザーをGoogleのログインページにリダイレクトした後、GoogleがログインユーザーのないウェブアプリケーションにGmailとすべての関連するGoogleサービスをウェブブラウザで許可するだけです。
次のコードも、ウェブアプリケーション認証の副作用としてGmailにログインします。私はOWINの設定オプションがたくさんあることがわかります。達成可能と信じています。
public partial class Startup
{
private double _expirationTimeCookies = 30; // minutes - sliding expiration
public static ApplicationUserManager ApplicationUserManagerCreate(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
var userStore = new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>());
var tokenProvider = new DataProtectorTokenProvider<ApplicationUser>(options.DataProtectionProvider.Create("ASP.NET Identity"));
ApplicationUserManager manager = new ApplicationUserManager(userStore);
manager.EmailService = new EmailService();
manager.SmsService = new SmsService();
var dataProtectionProvider = options.DataProtectionProvider;
if (dataProtectionProvider != null)
{
manager.UserTokenProvider = tokenProvider;
}
return ApplicationUserManager.Create(tokenProvider, manager);
}
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManagerCreate);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
ExpireTimeSpan = TimeSpan.FromMinutes(_expirationTimeCookies),
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(_expirationTimeCookies),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager, Helpers.IdentityExtensions.OnlineSettingsForAccount(user.Id)))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "xxxxxxxxxx.apps.googleusercontent.com",
ClientSecret = "xxxxxxx",
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnApplyRedirect = delegate(GoogleOAuth2ApplyRedirectContext context)
{
string redirect = context.RedirectUri;
redirect += "&prompt=select_account";
context.Response.Redirect(redirect);
}
},
});
}
}
あなたのアプリは公共のコンピュータで動作し、消費者がログアウトするのを忘れた場合、次のユーザーは以前のユーザーのGmailや他のGoogleサービスを開くことができないようにしたいと考えていますか? – CodeCaster
そして、どのようにGoogleは彼がGoogleサービスにログインすることなく、そのユーザーを確認するのだろうか? – Evk
@CodeCasterはい、正確です。 – qub1n