A sample web application for authentication using Kitura-Credentials
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.
This section is only relevant to Facebook and Google login. If you are only interested in HTTP authentication, you can skip this section.
This sample application authenticates with Facebook and Google. In order to do that, application instances must be created on Facebook and Google websites.
-
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. -
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
- 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
-
Go to Google developers console page, and create a new project.
-
Go to
Credentials
tab, clickCreate credentials
and chooseOAuth client ID
. -
Tap
Configure consent screen
and fill in the details. -
Back to
Credentials
, chooseWeb application
as your application type. In order to enable callbacks from Google, type your server URL plus/login/google/callback
inAuthorized redirect URIs
- this is required to make Google authentication work. -
Now you should see the app you just created in
Credentials
tab. Click on its name, and copy Client ID and Client secret toPagesCredentials.swift
:
let googleClientId = // Put Client Id here
let googleClientSecret = // Put Client Secret here
- Set your Google callback URL in
PagesCredentials.swift
:
let googleCallbackUrl = // Put your callback URL here
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.
-
For HTTP authentication, open http://localhost:8090/private/api/data. For this path, Digest authentication will be performed.
-
For HTTP Basic authentication, open your browser at http://localhost:8090/private/basic/api/data.
This sample app is licensed under Apache 2.0. Full license text is available in LICENSE.