public async Task <TokenModel> Handle(Renew request, CancellationToken cancellationToken) { RefreshToken refreshToken; try { refreshToken = RefreshToken.Parse(request.Model.RefreshToken); } catch (Exception exception) { throw new InvalidCredentialException(exception); } Session session = await dbContext.Sessions .Include(x => x.Account) .SingleOrDefaultAsync(x => x.Uuid == refreshToken.Id, cancellationToken); if (session?.Key.Match(Convert.ToBase64String(refreshToken.Key)) != true) { throw new InvalidCredentialException(); } TokenModel model = authenticationService.GetToken(session); await dbContext.SaveChangesAsync(cancellationToken); return(model); }
public async Task <Unit> Handle(LogOut request, CancellationToken cancellationToken) { RefreshToken refreshToken; try { refreshToken = RefreshToken.Parse(request.Model.RefreshToken); } catch (Exception exception) { throw new InvalidCredentialException(exception); } Session session = await dbContext.Sessions .Include(x => x.Account) .SingleOrDefaultAsync(x => x.Uuid == refreshToken.Id, cancellationToken); if (session?.Key.Match(Convert.ToBase64String(refreshToken.Key)) != true || session.Account !.Id != appContext.Account !.Id) { throw new InvalidCredentialException(); } dbContext.Sessions.Remove(session); await dbContext.SaveChangesAsync(cancellationToken); return(Unit.Value); }