public virtual ActionResult Login() { //get current application name string oAppName = base.GetAppNameByDomain(base.ReturnUrl); ViewBag.AppName = oAppName; //get fb client DotNetOpenAuth.ApplicationBlock.FacebookClient FBClient = GetFBClient(oAppName); //validate autentication DotNetOpenAuth.OAuth2.IAuthorizationState authorization = FBClient.ProcessUserAuthorization(); if (authorization == null) { //user is not login FBClient.RequestUserAuthorization(scope: new[] { DotNetOpenAuth.ApplicationBlock.FacebookClient.Scopes.UserAboutMe, DotNetOpenAuth.ApplicationBlock.FacebookClient.Scopes.Email, DotNetOpenAuth.ApplicationBlock.FacebookClient.Scopes.UserBirthday }); } else { //get social user info DotNetOpenAuth.ApplicationBlock.IOAuth2Graph oauth2Graph = FBClient.GetGraph( authorization, new[] { DotNetOpenAuth.ApplicationBlock.FacebookGraph.Fields.Defaults, DotNetOpenAuth.ApplicationBlock.FacebookGraph.Fields.Email, DotNetOpenAuth.ApplicationBlock.FacebookGraph.Fields.Picture, DotNetOpenAuth.ApplicationBlock.FacebookGraph.Fields.Birthday }); //create model login SessionManager.Models.Auth.User UserToLogin = base.GetUserToLogin(oauth2Graph, SessionManager.Models.Auth.enumProvider.Facebook); //login user UserToLogin = base.LoginUser(UserToLogin); //Add Log LogManager.ClientLog.AddLog(new LogManager.Models.LogModel() { User = UserToLogin.UserPublicId, Application = Auth.Interfaces.Constants.C_ApplicationName, Source = Request.Url.ToString(), IsSuccess = true, LogObject = UserToLogin, }); //return to site Response.Redirect(base.ReturnUrl.ToString()); } return(View()); }
public SessionManager.Models.Auth.User GetUserToLogin (DotNetOpenAuth.ApplicationBlock.IOAuth2Graph vSocialUser, SessionManager.Models.Auth.enumProvider vProvider) { SessionManager.Models.Auth.User ConvertUser = new SessionManager.Models.Auth.User() { Name = vSocialUser.FirstName, LastName = vSocialUser.LastName, Email = vSocialUser.Email, RelatedUserProvider = new List <SessionManager.Models.Auth.UserProvider>() { new SessionManager.Models.Auth.UserProvider() { ProviderId = vSocialUser.Id, Provider = vProvider, ProviderUrl = vSocialUser.Link != null?vSocialUser.Link.ToString() : null, } }, RelatedUserInfo = new List <SessionManager.Models.Auth.UserInfo>() { new SessionManager.Models.Auth.UserInfo() { UserInfoType = SessionManager.Models.Auth.enumUserInfoType.Birthday, Value = vSocialUser.BirthdayDT != null?vSocialUser.BirthdayDT.Value.ToString("yyyy/MM/dd") : string.Empty, }, new SessionManager.Models.Auth.UserInfo() { UserInfoType = SessionManager.Models.Auth.enumUserInfoType.Gender, Value = vSocialUser.GenderEnum == DotNetOpenAuth.ApplicationBlock.HumanGender.Female ? ((int)SessionManager.Models.Auth.enumGender.Female).ToString() : ((int)SessionManager.Models.Auth.enumGender.Male).ToString(), }, new SessionManager.Models.Auth.UserInfo() { UserInfoType = SessionManager.Models.Auth.enumUserInfoType.ProfileImage, Value = vSocialUser.AvatarUrl != null?vSocialUser.AvatarUrl.ToString() : string.Empty }, }, }; return(ConvertUser); }
public virtual ActionResult LoginCallBack() { //get return url Uri oReturnUrl = base.ReturnUrl; //get current application name string oAppName = base.GetAppNameByDomain(base.ReturnUrl); ViewBag.AppName = oAppName; //get fb client DotNetOpenAuth.ApplicationBlock.GoogleClient GMClient = GetGMClient(oAppName); //validate autentication DotNetOpenAuth.OAuth2.IAuthorizationState authorization = GMClient.ProcessUserAuthorization(); if (authorization != null) { DotNetOpenAuth.ApplicationBlock.IOAuth2Graph oauth2Graph = GMClient.GetGraph(authState: authorization); //create model login SessionManager.Models.Auth.User UserToLogin = base.GetUserToLogin(oauth2Graph, SessionManager.Models.Auth.enumProvider.Google); //login user UserToLogin = base.LoginUser(UserToLogin); //Add Log LogManager.ClientLog.AddLog(new LogManager.Models.LogModel() { User = UserToLogin.UserPublicId, Application = Auth.Interfaces.Constants.C_ApplicationName, Source = Request.Url.ToString(), IsSuccess = true, LogObject = UserToLogin, }); //return to site Response.Redirect(oReturnUrl.ToString()); } return(View()); }