#Stormpath is Joining Okta We are incredibly excited to announce that Stormpath is joining forces with Okta. Please visit the Migration FAQs for a detailed look at what this means for Stormpath users.
We're available to answer all questions at support@stormpath.com.
Vapor Authentication Demo
This is a demo for Vapor's authentication using its native Turnstile integration. This features:
- Username / Password Authentication
- Facebook / Google Login
- API Key authentication for API Endpoints
Want to try it out? Try out our live example!
Usage
Install Swift via Swiftenv
If you haven't already, install Swift via Swiftenv.
$ git clone https://github.com/kylef/swiftenv.git ~/.swiftenv
$ echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile
$ echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(swiftenv init -)"' >> ~/.bash_profileRun the Example
$ swiftenv install
$ swift build
$ .build/debug/AppThe application should run on port 8080 by default, so you should be able to access it from http://localhost:8080
The example code is commented and designed to be readable. Take a look through the code to see what it's doing!
Set up Facebook and Google Login
To learn more about Facebook and Google Login, check out the parent guide in the Turnstile documentation.
Create a Facebook Application
To get started, you first need to register an application with Facebook. After registering your app, go into your app dashboard's settings page. Add the Facebook Login product, and save the changes.
In the Valid OAuth redirect URIs box, type in your application's URL, postpended with /login/facebook/consumer. (eg, http://localhost:8080/login/facebook/consumer)
Create a Google Application
To get started, you first need to register an application with Google. Click "Enable and Manage APIs", and then the credentials tab. Create an OAuth Client ID for "Web".
Add your application's URL, postpended with /login/facebook/consumer to the Authorized redirect URIs list. (eg, http://localhost:8080/login/google/consumer)
Add your Client ID / Secret as Environment Variables
This example reads your Facebook and Google Client ID / Secret from environment variables, so you can make it portable. To add it to your application, first collect your Facebook / Google Client ID and Secret (sometimes called App ID), and set them as environment variables:
$ export FACEBOOK_CLIENT_ID=<Put Client ID here>
$ export FACEBOOK_CLIENT_Secret=<Put Client Secret here>
$ export GOOGLE_CLIENT_ID=<Put Client ID here>
$ export GOOGLE_CLIENT_Secret=<Put Client Secret here>This is also possible in Xcode under Edit Scheme > Arguments > Environment Variables.
Now run the application. Facebook and Google login should work!
Note: Facebook / Google Login are broken in Swift 3.0 on Linux, because of a Foundation bug. This demo should work in DEVELOPMENT-SNAPSHOT-2016-09-14-a or later, or in the official 3.0.1 release (not PREVIEW-1).
Contributing
We're always open to contributions! Feel free to join the Stormpath slack channel to discuss how you can contribute!
Stormpath
Turnstile is built by Stormpath, an API service for authentication, authorization, and user management. If you're building a website, API, or app, and need to build authentication and user management, consider using Stormpath for your needs. We're always happy to help!