Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Full-Stack Development with Swift

You're reading from   Hands-On Full-Stack Development with Swift Develop full-stack web and native mobile applications using Swift and Vapor

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788625241
Length 356 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ankur Patel Ankur Patel
Author Profile Icon Ankur Patel
Ankur Patel
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started with Server Swift FREE CHAPTER 2. Creating the Native App 3. Getting Started with Vapor 4. Configuring Providers, Fluent, and Databases 5. Building a REST API using Vapor 6. Consuming API in App 7. Creating Web Views and Middleware 8. Testing and CI 9. Deploying the App 10. Adding Authentication 11. Building a tvOS App 12. Other Books You May Enjoy

Adding authentication flow to iOS app


Currently, our iOS will be broken as we have added password and token-based authentication to our Vapor server. We will need to update the iOS such that we ask the user for their email and password on launching of the app and use that to generate a token. Then, we save the token in the UserDefaults of the app and send this token to any request our API make from our app.

Since UserDefaults can only be accessed by the app itself, it is safe enough for our Shopping List app, but for a production-ready app, you might want to consider Keychain API to securely store the token. So let's dive into the app and see how we can update it to support token-based authentication and get it working again:

  1. First, open the iOS ShoppingList project in Xcode and open the Request.swift file. We will be updating the request method so that we can pass headers in the HTTP request as well. We will do this by updating the function signature to the following:
func request(url: String...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image