Added tests for Session based API usage.
Integrated changes from twofactor