Task IRefreshTokenHandler.SaveRefreshTokenAsync(RefreshTokenInfo tokenInfo) { this.msAccountStatus = MSAccountStatus.Connected; return(Task.Factory.StartNew(() => { using (UsersContext db = new UsersContext()) { MSAccount msAccount = db.MSAccounts.FirstOrDefault(u => u.UserName == this.User.Identity.Name); if (msAccount != null) { if (tokenInfo.UserId != msAccount.MSUserId) { throw new LiveAuthException("invalid_user", "The account Id from the ticket does not match the current connected user."); } msAccount.RefreshToken = tokenInfo.RefreshToken; db.Entry(msAccount).State = System.Data.EntityState.Modified; } else { // Insert name into the profile table db.MSAccounts.Add(new MSAccount { MSUserId = tokenInfo.UserId, RefreshToken = tokenInfo.RefreshToken, UserName = this.User.Identity.Name }); } db.SaveChanges(); } })); }
Task <RefreshTokenInfo> IRefreshTokenHandler.RetrieveRefreshTokenAsync() { return(Task.Factory.StartNew <RefreshTokenInfo>(() => { RefreshTokenInfo token = null; using (UsersContext db = new UsersContext()) { MSAccount msAccount = db.MSAccounts.FirstOrDefault(u => u.UserName == this.User.Identity.Name); if (msAccount != null) { token = new RefreshTokenInfo(msAccount.RefreshToken, msAccount.MSUserId); this.msAccountStatus = MSAccountStatus.Connected; } } return token; })); }
public ActionResult DisconnectMicrosoft() { if (this.MSAccountStatus != Controllers.MSAccountStatus.NotConnected) { // Remove the account association using (UsersContext db = new UsersContext()) { MSAccount msAccount = db.MSAccounts.FirstOrDefault(u => u.UserName == this.User.Identity.Name); if (msAccount != null) { db.MSAccounts.Remove(msAccount); db.SaveChanges(); } } this.msAccountStatus = MSAccountStatus.NotConnected; } this.MSAuthClient.ClearSession(this.HttpContext); this.Response.Redirect(this.SiteRootPath + "account/connectmicrosoft"); return(null); }
private async Task <ActionResult> BuildMSAccountPageView(string[] scopes, AccountDataContent content) { MSAccountStatus accountStatus = this.MSAccountStatus; MSAccountPageModel model = new MSAccountPageModel() { Status = accountStatus, AjaxClientURL = this.AjaxClientPath, ShowContactsURL = this.ShowContactsPath }; if (accountStatus == MSAccountStatus.Connected) { await this.PopulateMSAccountData(model, content); } else { Dictionary <string, string> options = new Dictionary <string, string>(); options["state"] = "connect"; model.LoginUrl = this.MSAuthClient.GetLoginUrl(scopes, this.SiteRootPath + "account/connectcallback", options); } return(View("MSAccountPage", model)); }
Task<RefreshTokenInfo> IRefreshTokenHandler.RetrieveRefreshTokenAsync() { return Task.Factory.StartNew<RefreshTokenInfo>(() => { RefreshTokenInfo token = null; using (UsersContext db = new UsersContext()) { MSAccount msAccount = db.MSAccounts.FirstOrDefault(u => u.UserName == this.User.Identity.Name); if (msAccount != null) { token = new RefreshTokenInfo(msAccount.RefreshToken, msAccount.MSUserId); this.msAccountStatus = MSAccountStatus.Connected; } } return token; }); }
Task IRefreshTokenHandler.SaveRefreshTokenAsync(RefreshTokenInfo tokenInfo) { this.msAccountStatus = MSAccountStatus.Connected; return Task.Factory.StartNew(() => { using (UsersContext db = new UsersContext()) { MSAccount msAccount = db.MSAccounts.FirstOrDefault(u => u.UserName == this.User.Identity.Name); if (msAccount != null) { if (tokenInfo.UserId != msAccount.MSUserId) { throw new LiveAuthException("invalid_user", "The account Id from the ticket does not match the current connected user."); } msAccount.RefreshToken = tokenInfo.RefreshToken; db.Entry(msAccount).State = System.Data.EntityState.Modified; } else { // Insert name into the profile table db.MSAccounts.Add(new MSAccount { MSUserId = tokenInfo.UserId, RefreshToken = tokenInfo.RefreshToken, UserName = this.User.Identity.Name }); } db.SaveChanges(); } }); }
public ActionResult DisconnectMicrosoft() { if (this.MSAccountStatus != Controllers.MSAccountStatus.NotConnected) { // Remove the account association using (UsersContext db = new UsersContext()) { MSAccount msAccount = db.MSAccounts.FirstOrDefault(u => u.UserName == this.User.Identity.Name); if (msAccount != null) { db.MSAccounts.Remove(msAccount); db.SaveChanges(); } } this.msAccountStatus = MSAccountStatus.NotConnected; } this.MSAuthClient.ClearSession(this.HttpContext); this.Response.Redirect(this.SiteRootPath + "account/connectmicrosoft"); return null; }