The Apigility uses OAuth to authenticate users... Don't steal too much ideas from it ;-)