Skip to content

PerfectExamples/Perfect-Authentication-Demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Perfect-Authentication Demo

Perfect logo

Perfect logo Perfect logo Perfect logo Perfect logo

Swift 3.0 Platforms OS X | Linux License Apache Twitter Join the chat at https://gitter.im/PerfectlySoft/Perfect Slack Status GitHub version

Demonstrating the OAuth2 Library for Perfect

This project provides OAuth2 demo of the Perfect Authentication libraries and select OAuth2 provider drivers - Facebook, Google, GitHub.

Full documentation can be found at http://www.perfect.org/docs/OAuth2.html

This package builds with Swift Package Manager and is part of the Perfect project. It was written to be stand-alone and so does not require PerfectLib or any other components.

Ensure you have installed and activated the latest Swift 3.0 tool chain.

Setup

Download this repo, clone it, or import it using Perfect Assistant. Build, configure the system with your AppID's and secrets, and run.

git clone https://github.com/PerfectExamples/Perfect-Authentication-Demo
cd Perfect-Authentication-Demo
swift build
.build/debug/Perfect-Authentication-Demo

Alternatively, build the Xcode project with swift package generate-xcodeproj.

If you choose to generate an Xcode Project, you MUST change to the executable target AND set the custom working directory to the project directory for its scheme in order for the web routes to work properly.

Configuration

Each provider needs an "appid", also known as a "key", and a "secret". These are usually generated by the OAuth Host, such as Facebook, GitHub and Google developer consoles. These values, as well as an "endpointAfterAuth" and "redirectAfterAuth" value must be set for each provider you wish to use. If you leave any unset, the authentication will fail.

These settings are configured by removing the ".default" extension from the "ApplicationConfiguration.json.default" file in the "config" directory, then populating the values as needed.

The default file looks like this:

{
	"facebookAppID": "---",
	"facebookSecret": "---",
	"facebookEndpointAfterAuth": "http://localhost:8181/auth/response/facebook",
	"facebookRedirectAfterAuth":"http://localhost:8181/",

	"githubKey": "---",
	"githubSecret": "---",
	"githubEndpointAfterAuth": "http://localhost:8181/auth/response/github",
	"githubRedirectAfterAuth":"http://localhost:8181/",

	"googleKey": "---",
	"googleSecret": "---",
	"googleEndpointAfterAuth": "http://localhost:8181/auth/response/google",
	"googleRedirectAfterAuth":"http://localhost:8181/"
}

Replace the --- values with those from your own accounts.

Running

Once the demo has been configured, it can be run from the command line, or from Xcode.

It can then be accessed from a web browser at http://localhost:8181.

The first page you will see will have the following:

SessionID: <<SessionID>>

Login Type:

UserID:

UserName:

Picture:

AccessToken:

These values however will be populated upon login with one of the providers via the buttons.

Logging out will terminate the session, and start a new session without any information gained from a login with a provider.

Note that this demo uses the "MemorySessions" driver, so terminating the demo and restarting it will delete all existing sessions.

Further Information

For more information on the Perfect project, please visit perfect.org.