Kodeco Forums

Server Side Swift with Vapor – First 16 Chapters Now Available!

The first early access release of our Server Side Swift with Vapor book is now available!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5230-server-side-swift-with-vapor-first-16-chapters-now-available

Enjoying the book. Well done.

Ran into a small bump in Chapter 6: Configuring a Database when attempting to connect to a MySQL database running in a Docker container on my host machine. (Caveat: I’m no expert on MySQL, or anything else for that matter…)

Apparently, the more recent versions of MySQL use a default authentication plugin of caching_sha2_password, which the Vapor code in MySQLConnection+Authenticate.swift does not like. The only allowed authentication option in the Vapor code is mysql_native_password.

So, to make Vapor work with MySQL running in a Docker container just add a command-line option when you create the container. Add --default-authentication-plugin=mysql_native_password to the end of the Docker command that creates the container. As in:

docker run --name mysql -e MYSQL_USER=vapor -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=vapor -p 3306:3306 -d mysql/mysql-server --default-authentication-plugin=mysql_native_password

I should probably add that this is with Vapor MySQL version 3.0.0-rc2.2. And the MySQL documentation for default-authentication-plugin.

@gazingatnavel good spot. I’ve raised an issue on GH for this. You can also specify an older version of MySQL as well if you want:

docker run --name mysql -e MYSQL_USER=vapor -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=vapor -p 3306:3306 -d mysql/mysql-server:5.7

@0xtim excellent point! I looked for something like that at the MySQL Docker repository, but for some reason it didn’t click with me. Looking at it again, there it is, staring me right in the face. Doh!

Thanks for raising the issue with the Vapor folks on GitHub.

And, OBTW, the Vapor MySQL code works just fine when deploying to Vapor Cloud. Perhaps they’re using an older version of MySQL or have the default authentication plugin set to mysql_native_password.

Yeah I imagine they’ll hold back the MySQL release to something that works! :sweat_smile:

I hope the table of contents come back in the PDF version in the final release!

Yeah apparently the generation tool is borked, but being looked into!

Hey guys, will the book cover auth with ios app?

@skai do you mean logging users in to the iOS and app sending authenticated requests to protected routes in the API? If so I’ve just finished the chapter that does just that!

1 Like

Yup! You mean something like registration and login? And is it basic auth or jwt/oauth thing?

It’s basic auth followed by bearer authentication with tokens