Server Side Swift with Vapor: Registering Users over | Ray Wenderlich

In this screencast, you’ll learn how to securely register users using Vapor and set usernames and passwords over SSL.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5015-server-side-swift-with-vapor-registering-users-over-ssl
1 Like

Hi Ray,
this a great screencast as all the others about Vapor and a really important one.
Unfortunately there is no link to download the material.
Thank you

Hi Ray! If I have my Vapor app on Heroku and I’m using the default app domain that they give me, which comes by default with https, I don’t have to do the certificates thing, right?

@leynan The materials should be available now! Thanks!

@diefer91 Yes, that is one of the nice things about Heroku actually! :] I wanted to include these instructions anyway for folks who don’t use Heroku, etc.

Hi Ray,

I was did try the SSL config for vapor and https://localhost:3000 is working all good on the browser on my mac.
Now I build a simple api for iOS app using vapor and SSL, but when i try to use this in IOS
via code
let url = NSURL(string: “https://localhost:3000/”)!
let request = NSMutableURLRequest(url: url as URL)
request.httpMethod = “GET”
let session = URLSession.shared

           let dataTask = session.dataTask(with: request as URLRequest) { (data, response, error) in
        print(response)
        print(error?.localizedDescription)
        
    }
    dataTask.resume()

i get the following error:
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
nil
Optional(“An SSL error has occurred and a secure connection to the server cannot be made.”)

kindly let me know i can proceed here to get a successful fetch from server.

The issue is you need to have a cert that is trusted on your iOS device. By default iOS will not accept self-signed certs unless you mark it as trusted (we did this for macOS in the video).

You have a few options here:

  1. Test over HTTP instead of HTTPs on your iOS app (will work without doing anything special, and you can switch to HTTPs when you deploy with real certs).
  2. Set your self-signed cert as trusted on your iOS device, which I think you may be able to do by browsing in Safari to your machine’s IP address on your local network and accepting the cert. I think you may need to change the URL and Common Name (CN) of the cert from “localhost” to the IP address of your local machine. I found some discussion here that may help: HTTPS and IP Addresses | Apple Developer Forums

Unfortunately I don’t have time to test this at the moment, but if you (or anyone else) gets this working please post here so others can benefit. Thanks!

There’s a good alternative to self-signed cert’s: https://letsencrypt.org/
Please make sure to check it out, that’s definitely worth looking at.

You basically install command line tool, specify your domain name and get free certs for that domain, that are recognized by browsers and iOS.