0
Azure Active Directoryを使用して登録を成功させると、自動的に自分のアプリケーションにログインします。現時点では、ユーザーはログインページにリダイレクトされます。AADにサインアップした後の自動ログイン
レジスタのコードは次のとおりです。
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
Microsoft.Azure.ActiveDirectory.GraphClient.IUser newUser = new User();
activeDirectoryClient = AuthenticationHelper.GetActiveDirectoryClientAsApplication();
newUser.DisplayName = model.Name + " " + model.Surname;
newUser.UserPrincipalName = model.UserName;
newUser.AccountEnabled = true;
newUser.MailNickname = model.Name;
newUser.PasswordProfile = new PasswordProfile
{
Password = model.Password,
ForceChangePasswordNextLogin = false
};
newUser.UsageLocation = "US";
try
{
activeDirectoryClient.Users.AddUserAsync(newUser);
}
catch (Exception e)
{
Console.WriteLine("\nError creating new user {0} {1}", e.Message,
e.InnerException != null ? e.InnerException.Message : "");
}
return RedirectToAction("Login", "Account");
}
// If we got this far, something failed, redisplay form
return View();
}
ログイン用のコードです:
public void Login()
{
// Send an OpenID Connect sign-in request.
if (!Request.IsAuthenticated)
{
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
}
任意の助けいただければ幸い:)