Slide 121
Slide 121 text
import HexavilleAuth
let facebookProvider = FacebookAuthorizationProvider(
path: "/auth/facebook",
consumerKey: ProcessInfo.processInfo.environment[“FACEBOOK_APP_ID"]! ?? "",
consumerSecret: ProcessInfo.processInfo.environment[“FACEBOOK_APP_SECRET"]!,
callbackURL: CallbackURL(baseURL: “http://foo.bar”, path: "/auth/facebook/callback"),
scope: "public_profile,email"
) { credentianl, user, req, ctx in
return Response(body: "access token is: \(credentianl.accessToken)")
}
var auth = HexavilleAuth()
auth.add(facebookProvider)
app.use(session)
app.use(HexavilleAuth.AuthenticationMiddleware())
app.use(auth) // Available /auth/facebook and /auth/facebook /callback
app.use(auth) { request, context in
print(context.isAuthenticated())
}
Code Example
4. Create Practical Web App with Hexaville