HexavilleAuth is an Authentication(OAuth, simple password based) framework for Hexaville.
HexavilleAuth recognizes that each application has unique authentication requirements. It allows individual authentication mechanisms to be packaged as plugins which it consumes.
Plugins can range from a simple password based authentication or, authentication using OAuth (via Facebook, Github OAuth provider, etc.).
HexavilleAuth automatically creates resources for authorize/callback for each sns platforms, So you can embed sns authentication features into your Hexaville application very quickly.
Authentication Methods
Email+password
Authorization Methods
OAuth1
OAuth2
Supported SNS Platforms
OAuth2
Facebook
Github
Google
Instagram
OAuth1
Twitter
Installation
Just add .Package(url: "https://github.com/Hexaville/HexavilleAuth.git", majorVersion: 0, minor: 1) into your Package.swift
Here is an example code for facebook oauth authorization with HexavilleFramework
import Foundation
import HexavilleAuth
import HexavilleFramework
let app = HexavilleFramework()
var auth = HexavilleAuth()
let APP_URL = ProcessInfo.processInfo.environment["APP_URL"] ?? "http://localhost:3000"
let facebookProvider = FacebookAuthorizationProvider(
path: "/auth/facebook",
consumerKey: ProcessInfo.processInfo.environment["FACEBOOK_APP_ID"] ?? "",
consumerSecret: ProcessInfo.processInfo.environment["FACEBOOK_APP_SECRET"] ?? "",
callbackURL: CallbackURL(baseURL: APP_URL, path: "/auth/facebook/callback"),
scope: "public_profile"
) { credential, user, request, context in
// here is called when the access_token got successfully from sns.
return Response(body: "\(user)")
}
auth.add(facebookProvider)
app.use(auth)
app.catch { error in
switch error {
case HexavilleAuthError.responseError(let response):
return Response(body: response.body.asData())
default:
return Response(body: "\(error)")
}
}
try app.run()
Getting loginUser object on the every requests.
If you register HexavilleAuth.AuthenticationMiddleware and loginUser information is stored in the session, You can get it from ApplicationContext as LoginUser Object.
LoginUser
public struct LoginUser {
public let id: String
public let name: String
public let screenName: String?
public let email: String?
public let picture: String?
public let raw: [String: Any]
}
Example
import Foundation
import HexavilleAuth
import HexavilleFramework
let app = HexavilleFramework()
var auth = HexavilleAuth()
let APP_URL = ProcessInfo.processInfo.environment["APP_URL"] ?? "http://localhost:3000"
let twitterProvider = TwitterAuthorizationProvider(
path: "/auth/twitter",
consumerKey: ProcessInfo.processInfo.environment["TWITTER_APP_ID"] ?? "",
consumerSecret: ProcessInfo.processInfo.environment["TWITTER_APP_SECRET"] ?? "",
callbackURL: CallbackURL(baseURL: APP_URL, path: "/auth/twitter/callback"),
scope: ""
) { credential, user, request, context in
return Response(body: "\(user)")
}
app.use(HexavilleAuth.AuthenticationMiddleware()) // register to get loginUser Object
app.use { req, context in
print(context.isAuthenticated()) // => true
print(context.loginUser) // Get the loginUser object
return .next(req)
}
auth.add(twitterProvider)
app.use(auth)
try app.run()
HexavilleAuth
HexavilleAuth is an Authentication(OAuth, simple password based) framework for Hexaville.
HexavilleAuth recognizes that each application has unique authentication requirements. It allows individual authentication mechanisms to be packaged as plugins which it consumes.
Plugins can range from a simple password based authentication or, authentication using OAuth (via Facebook, Github OAuth provider, etc.).
HexavilleAuth automatically creates resources for authorize/callback for each sns platforms, So you can embed sns authentication features into your Hexaville application very quickly.
Authentication Methods
Authorization Methods
Supported SNS Platforms
OAuth2
OAuth1
Installation
Just add
.Package(url: "https://github.com/Hexaville/HexavilleAuth.git", majorVersion: 0, minor: 1)
into your Package.swiftUsage
Here is an example code for facebook oauth authorization with HexavilleFramework
Getting loginUser object on the every requests.
If you register
HexavilleAuth.AuthenticationMiddleware
and loginUser information is stored in the session, You can get it fromApplicationContext
asLoginUser
Object.LoginUser
Example
Try Example!
Here is an official full example code.
Install and Build Example
Launch Server
Resources
Try to access following resources to authentication/authorization with Browser!
Create Your Custom Authorization/Authentication Provider
You can create Custom Authorization/Authentication Provider with
OAuthXAuthorizationProvidable
/AuthenticationProvidable
Oauth2
OAuth2Authorization
here is an example for Salesforce Authorization.
Use it!
License
HexavilleAuth is released under the MIT license. See LICENSE for details.