2016-10-07 4 views
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); 
     } 
    } 

任意の助けいただければ幸い:)

答えて

0

私の理解に基づいて、 registerとlogin-inは、Webアプリケーションの2つの異なる概念です。登録後にページのログインにリダイレクトすることが期待されています。それらを使用するために混在させるべきではありません。

Azure Active Directoryは、信頼する側の認証にOpenId connectを使用することをサポートしていますが、ユーザーがサインインしなくても認証をサポートしていません。

関連する問題