public virtual IEnumerable CompleteAuthentication(PXAdapter adapter) { PXLongOperation.StartOperation(this, delegate { User.Cache.Clear(); var tokenHandler = PXGraph.CreateInstance <UserTokenHandler>(); BoxUserTokens boxUser = PXCache <BoxUserTokens> .CreateCopy(User.Select()); var userInfo = BoxUtils.GetUserInfo(tokenHandler).Result; boxUser.BoxUserID = userInfo.Id; boxUser.BoxEmailAddress = userInfo.Login; User.Update(boxUser); Actions.PressSave(); }); return(adapter.Get()); }
public void SessionAuthenticated(object sender, SessionAuthenticatedEventArgs e) { // We use a separate connection to ensure that the token gets persisted to the DB, regardless of any transaction rollback. // It could potentially happen that the token needs to get refreshed while a file is uploaded, but that this upload ultimately gets rolled back due to another // error later during the caller graph persisting process. If we use the current connection scope we have no control over this update. using (new PXConnectionScope()) { BoxUserTokens currentUser = PXCache <BoxUserTokens> .CreateCopy(GetCurrentUser()); currentUser.AccessToken = e.Session.AccessToken; currentUser.RefreshToken = e.Session.RefreshToken; currentUser.RefreshTokenDate = PXTimeZoneInfo.UtcNow; Caches[typeof(BoxUserTokens)].Update(currentUser); Caches[typeof(BoxUserTokens)].Persist(PXDBOperation.Update); } }
public void SessionInvalidated(object sender, EventArgs e) { //Clear out stored token if any. using (new PXConnectionScope()) { BoxUserTokens currentUser = GetCurrentUser(); if (currentUser != null) { currentUser = PXCache <BoxUserTokens> .CreateCopy(currentUser); currentUser.AccessToken = null; currentUser.RefreshToken = null; Caches[typeof(BoxUserTokens)].Update(currentUser); Caches[typeof(BoxUserTokens)].Persist(PXDBOperation.Update); } } throw new PXException(Messages.BoxUserNotFoundOrTokensExpired); }