Giter Site home page Giter Site logo

therickys93 / turnstile-vapor-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stormpath/turnstile-vapor-example

0.0 2.0 0.0 84 KB

A demo of Vapor Authentication powered by Turnstile

Home Page: https://github.com/stormpath/Turnstile

License: Apache License 2.0

Swift 94.29% CSS 5.71%

turnstile-vapor-example's Introduction

#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 [email protected].

Vapor Authentication Demo

Slack Status

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_profile

Run the Example

$ swiftenv install
$ swift build
$ .build/debug/App

The 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!

turnstile-vapor-example's People

Contributors

edjiang avatar dan-zheng avatar brentstormpath avatar

Watchers

James Cloos avatar Riccardo Crippa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.