With a few narrow exceptions (in particular, financial services) an employer is not legally obliged to provide a reference.
Your employer must not victimise you by refusing to give you a satisfactory reference, for example, because you have alleged discrimination or engaged in whistleblowing. This would be against the law. You can find out more about what amounts to victimisation.
Where a reference is given, the employer has an implied duty of care to both you as the ex-employee and also to the prospective employer to take reasonable care that the reference is true, accurate and fair. You may be able to bring a civil case for negligence if you suffer damage as a result of an inaccurate reference (e.g. an unjustified reference causes a job offer to be withdrawn).