/Kitura-Credentials-Sample

A sample web application for authentication using Kitura-Credentials

Primary LanguageSwiftApache License 2.0Apache-2.0

Kitura-Credentials-Sample

A sample web application for authentication using Kitura-Credentials

Mac OS X Linux Apache 2

Summary

This is a sample Kitura application for authentication using Kitura-Credentials. See instructions for Installation on OS X or Installation on Linux.

This sample shows both redirecting authentication with sessions using Facebook and Google login, and non-redirecting HTTP Basic and Digest authentication.

Running Kitura-Credentials-Sample with Facebook and Google login

This section is only relevant to Facebook and Google login. If you are only interested in HTTP authentication, you can skip this section.

Create an application instance on Facebook and Google

This sample application authenticates with Facebook and Google. In order to do that, application instances must be created on Facebook and Google websites.

Facebook

  1. To create an application instance on Facebook's website, go to Facebook developers page page, and add a new app. Choose Website as your platform. Follow the steps to create a new app.

  2. Go to Developer dashboard and copy App Id and App Secret to PagesCredentials.swift:

let fbClientId = // Put App Id here
let fbClientSecret = // Put App Secret here
  1. Configure Facebook callback URL in PagesCredentials.swift. It should be your Site URL as you configured it on Facebook plus /login/facebook/callback:
let fbCallbackUrl = // Put your callback URL here
Google
  1. Go to Google developers console page, and create a new project.

  2. Go to Credentials tab, click Create credentials and choose OAuth client ID.

  3. Tap Configure consent screen and fill in the details.

  4. Back to Credentials, choose Web application as your application type. In order to enable callbacks from Google, type your server URL plus /login/google/callback in Authorized redirect URIs - this is required to make Google authentication work.

  5. Now you should see the app you just created in Credentials tab. Click on its name, and copy Client ID and Client secret to PagesCredentials.swift:

let googleClientId = // Put Client Id here
let googleClientSecret = // Put Client Secret here
  1. Set your Google callback URL in PagesCredentials.swift:
let googleCallbackUrl = // Put your callback URL here

Build and run

  1. make run

You should see message Listening on port 8090. The result executable is located in .build/debug directory: ./.build/debug/KituraCredentialsSample 2. For Facebook/Google login, open your browser at http://localhost:8090/private/pages/data.

  1. For HTTP authentication, open http://localhost:8090/private/api/data. For this path, Digest authentication will be performed.

  2. For HTTP Basic authentication, open your browser at http://localhost:8090/private/basic/api/data.

License

This sample app is licensed under Apache 2.0. Full license text is available in LICENSE.