This is actually part of server-side implementaion for the previous post: How to authenticate from a mobile application to an existing web pplication We are going to create an ASP.NET MVC action as a JSON API to authenticate a mobile client.
The Token Interface
First, let’s create a token service interface for our API Controller. We will be using dependency injection pattern.
|
The API Controller
Our API controller can now use the token authentication service as simple as
|
Unit Test
Now that we have our interface, and we have our controller. Let’s create an unit test first, yes, we don’t actually need to implement our interface when we write our test. We can actually assign someone to help us to implement the interface later.
Alright, below is one of our test. We will use Moq to help us mock our interface.
|