Implementing a login request to a web service
Let's assume that a colleague is developing a web service, but it is not finished yet. However, we already know what the API will look like. There will be an endpoint for the login. The URL will be https://awesometodos.com/login
; it will take two parameters, a username and password, and it will return a token that has to be used with each call to the API.
We need a test that asserts that the token, returned from the login call, is stored somewhere for later use. Tokens should be stored in the iOS keychain. Keychain access is managed by a very low-level API. This means that it is a bit complicated to build a class accessing keychain items (but it's easier than you might think). Because of this, there are a lot of available open source frameworks for reading from and writing to the keychain. Implementing keychain access is beyond the scope of this book. Instead, we will add a protocol that defines the methods that the keychain manager should implement...