Emil Moe I haven't implemented one from scratch, but I recently went through some of the code of this library (java) which is simple, handles common cases and is easy to follow through.
For a higher level overview of SAML flow, this introduction was really great.