public dynamic Process(NancyModule nancyModule, AuthenticateCallbackData model) { Response response; if (model.ReturnUrl != null) { response = nancyModule.Response.AsRedirect("~" + model.ReturnUrl); } else { response = nancyModule.AsRedirectQueryStringOrDefault("~/"); if (nancyModule.IsAuthenticated()) { response = nancyModule.AsRedirectQueryStringOrDefault("~/account/#identityProviders"); } } if (model.Exception != null) { nancyModule.Request.AddAlertMessage("error", model.Exception.Message); } else { UserInformation information = model.AuthenticatedClient.UserInformation; var claims = new List <Claim>(); claims.Add(new Claim(ClaimTypes.NameIdentifier, information.Id)); claims.Add(new Claim(ClaimTypes.AuthenticationMethod, model.AuthenticatedClient.ProviderName)); if (!String.IsNullOrEmpty(information.UserName)) { claims.Add(new Claim(ClaimTypes.Name, information.UserName)); } if (!String.IsNullOrEmpty(information.Email)) { claims.Add(new Claim(ClaimTypes.Email, information.Email)); } nancyModule.SignIn(claims); } return(response); }
/// <summary> /// Called when we receive a callback from a social provider /// </summary> public dynamic Process(NancyModule nancyModule, AuthenticateCallbackData model) { if (model.Exception == null) { var userInfo = model.AuthenticatedClient.UserInformation; var providerName = model.AuthenticatedClient.ProviderName; // See if we already know about this provider/id UserIdentity userIdentity = null;// ReadStore.UserIdentities.FindAllByProviderAndId(providerName, userInfo.Id).FirstOrDefault(); // Deal with an unknown/already known social identity return(userIdentity == null ? HandleUnknownIdentity(nancyModule) : HandleKnownIdentity(userIdentity, nancyModule, model.ReturnUrl)); } // An error occured, we didn't get permission, etc... //nancyModule.AddAlertMessage("error", model.Exception.Message); // If a user was logged in, he got here from the linking page // If the user isn't logged in, he got here from the login page return(nancyModule.Response.AsRedirect(nancyModule.IsAuthenticated() ? "~/account/identity" : "~/account/login")); }