A sample web application for authentication using Kitura-Credentials
🚫 This project is no longer maintained. Replacement credentials sample can be found as part of Kitura-Sample
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, and authentication with Facebook or Google OAuth token.
KituraCredentialsDemo application is a sample iOS application that shows the client side of authentication with OAuth tokens.
The latest version of Kitura-Credentials-Sample requires Swift 4.0. You can download this version of the Swift binaries by following this link. Compatibility with other Swift versions is not guaranteed.
- Running Kitura-Credentials-Sample with Facebook and Google web login
- Build and run Kitura-Credentials-Sample
- Running KituraCredentialsDemo
- License
This section is only relevant to Facebook and Google web login. If you are only interested in HTTP or OAuth token authentication, you can skip this section.
In order to use Facebook and Google web login, 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
swift build
You should see message Listening on port 8080. The result executable is located in .build/debug
directory: ./.build/debug/KituraCredentialsSample
-
For Facebook/Google login, open your browser at http://localhost:8080/private/pages/data.
-
For HTTP authentication, open http://localhost:8080/private/api/data. For this path, Digest authentication will be performed.
-
For HTTP Basic authentication, open your browser at http://localhost:8080/private/basic/api/data.
-
For Facebook/Google OAuth token authentication, run KituraCredentialsDemo as explained in the next section.
KituraCredentialsDemo application is a sample iOS application that shows the client side of authentication with OAuth tokens. After signing in using either Facebook or Google the user can request private data from Kitura-Credentials-Sample server. The app sends a request to /private/api/data with either Facebook or Google OAuth token.
In order to enable Facebook and Google sign in the app, you have to create application instances.
-
To create an application instance on Facebook's website, first go to Facebook's Quick Start for iOS page. Type
CredentialsDemo
as the name of your new Facebook app and click theCreate New Facebook App ID
button. -
On the screen that follows, in the
Configure your info.plist
section understep 2
, copy the information into yourinfo.plist
file. You can find theinfo.plist
file inConfiguration
folder of the Xcode project. If you have trouble finding theCFBundleURLType
key, note that Xcode changes theCFBundleURLType
key toURL types
when the key is entered. -
Next scroll to the bottom of the quick start page where it says
Supply us with your Bundle Identifier
and enter the app's bundle identifier. -
Once you entered the bundle ID on the Facebook quick start page, click
next
. That's it for the Facebook quick start setup.
-
Go to Enable Google services for your app page, and create a new project: type
CredentialsDemo
as the name of your new app, and enter the app's bundle id. -
Now press the
Continue and configure services
button. -
On the screen that follows, choose Google Sign-In service and press the
Enable Google Sign-In
button. -
Press the
Generate configuration files
button. On the next screen pressDownload GoogleService-Info.plist
. Drag the downloaded GoogleService-Info.plist file into theKituraCredentialsDemo
directory of KituraCredentialsDemo project. -
Open
Configuration/Info.plist
in Xcode. Under URL Types create a new item and paste your REVERSED_CLIENT_ID into the URL Schemes field (you can find your REVERSED_CLIENT_ID in theGoogleService-Info.plist
file). Create another new item and type your bundle identifier in the URL Schemes field.
Now configure LSApplicationQueriesSchemes in Info.plist: add an item with fbauth2
and another item with Google's REVERSED_CLIENT_ID.
After completing the above steps your Info.plist
file should look like this:
Figure 1. Info.plist file.
Go to the KituraCredentialsDemo directory and run:
pod install
This sample app is licensed under Apache 2.0. Full license text is available in LICENSE.