auth deploy

This commit is contained in:
2020-02-07 21:08:24 -06:00
parent 757b85cabb
commit 7a45538d69
25 changed files with 738 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
* routes file.
*/
const Middleware = [
"auth:Utility",
// 'MiddlewareName',

View File

@@ -0,0 +1,15 @@
/*
* GuestOnly Middleware
* -------------------------------------------------------------
* Allows the request to proceed unless there's an authenticated user
* in the session. If so, redirect to the auth flow destination if one
* exists. If not, redirect to the default login route.
*/
const Middleware = require('flitter-auth/middleware/GuestOnly')
class GuestOnly extends Middleware {
}
module.exports = GuestOnly

View File

@@ -0,0 +1,12 @@
const Middleware = require('flitter-auth/middleware/KeyAction')
/*
* KeyAction Middleware
* -------------------------------------------------------------
* Middleware for processing key actions.
*/
class KeyAction extends Middleware {
}
module.exports = exports = KeyAction

View File

@@ -0,0 +1,14 @@
/*
* Oauth2TokenOnly Middleware
* -------------------------------------------------------------
* Allows the request to proceed if a valid OAuth2 bearer token was
* provided. If not, return a JSON-encoded error message.
*/
const Middleware = require('flitter-auth/middleware/Oauth2TokenOnly')
class Oauth2TokenOnly extends Middleware {
}
module.exports = Oauth2TokenOnly

View File

@@ -0,0 +1,14 @@
/*
* ProviderRegistrationEnabled Middleware
* -------------------------------------------------------------
* Redirects the user to the login page if the registration page for
* a particular auth provider is not enabled.
*/
const Middleware = require('flitter-auth/middleware/ProviderRegistrationEnabled')
class ProviderRegistrationEnabled extends Middleware {
}
module.exports = ProviderRegistrationEnabled

View File

@@ -0,0 +1,15 @@
/*
* Auth ProviderRoute Middleware
* -------------------------------------------------------------
* Many auth routes specify the name of a particular auth provider to
* use. This middleware looks up the provider by that name and injects
* it into the request.
*/
const Middleware = require('flitter-auth/middleware/ProviderRoute')
class ProviderRoute extends Middleware {
}
module.exports = ProviderRoute

View File

@@ -0,0 +1,15 @@
/*
* UserOnly Middleware
* -------------------------------------------------------------
* Allows the request to proceed if there's an authenticated user
* in the session. Otherwise, redirects the user to the login page
* of the default provider.
*/
const Middleware = require('flitter-auth/middleware/UserOnly')
class UserOnly extends Middleware {
}
module.exports = UserOnly

View File

@@ -0,0 +1,15 @@
/*
* Auth Utility Middleware
* -------------------------------------------------------------
* This should be applied globally. Ensures basic things about the
* request are true. For example, it provides the auth session data
* and handles auth flow.
*/
const Middleware = require('flitter-auth/middleware/Utility')
class Utility extends Middleware {
}
module.exports = Utility

View File

@@ -0,0 +1,113 @@
/*
* Auth Form Routes
* -------------------------------------------------------------
* The routes here pertain to auth forms like register/login etc.
* The general structure is as follows:
*
* /auth/{provider name}/{action}
* Individual providers may be interacted with individually, therefore:
*
* /auth/flitter/register
*
* You can omit the provider name to use the default provider:
*
* /auth/register
*/
const index = {
prefix: '/auth',
middleware: [
],
get: {
'/:provider/register': [
'middleware::auth:ProviderRoute',
'middleware::auth:GuestOnly',
'middleware::auth:ProviderRegistrationEnabled',
'controller::auth:Forms.registration_provider_get',
],
'/register': [
'middleware::auth:ProviderRoute',
'middleware::auth:GuestOnly',
'middleware::auth:ProviderRegistrationEnabled',
'controller::auth:Forms.registration_provider_get',
],
'/:provider/login': [
'middleware::auth:ProviderRoute',
'middleware::auth:GuestOnly',
'controller::auth:Forms.login_provider_get',
],
'/login': [
'middleware::auth:ProviderRoute',
'middleware::auth:GuestOnly',
'controller::auth:Forms.login_provider_get',
],
'/:provider/logout': [
'middleware::auth:ProviderRoute',
'middleware::auth:UserOnly',
'controller::auth:Forms.logout_provider_clean_session',
// Note, this separation is between when the auth action has happened properly
// and before the user is allowed to continue. You can use it to add your own
// custom middleware for auth flow handling.
'controller::auth:Forms.logout_provider_present_success',
],
'/logout': [
'middleware::auth:ProviderRoute',
'middleware::auth:UserOnly',
'controller::auth:Forms.logout_provider_clean_session',
'controller::auth:Forms.logout_provider_present_success',
],
},
post: {
'/:provider/register': [
'middleware::auth:ProviderRoute',
'middleware::auth:GuestOnly',
'middleware::auth:ProviderRegistrationEnabled',
'controller::auth:Forms.registration_provider_create_user',
'controller::auth:Forms.registration_provider_present_user_created',
],
'/register': [
'middleware::auth:ProviderRoute',
'middleware::auth:GuestOnly',
'middleware::auth:ProviderRegistrationEnabled',
'controller::auth:Forms.registration_provider_create_user',
'controller::auth:Forms.registration_provider_present_user_created',
],
'/:provider/login': [
'middleware::auth:ProviderRoute',
'middleware::auth:GuestOnly',
'controller::auth:Forms.login_provider_authenticate_user',
'controller::auth:Forms.login_provider_present_success',
],
'/login': [
'middleware::auth:ProviderRoute',
'middleware::auth:GuestOnly',
'controller::auth:Forms.login_provider_authenticate_user',
'controller::auth:Forms.login_provider_present_success',
],
'/:provider/logout': [
'middleware::auth:ProviderRoute',
'middleware::auth:UserOnly',
'controller::auth:Forms.logout_provider_clean_session',
'controller::auth:Forms.logout_provider_present_success',
],
'/logout': [
'middleware::auth:ProviderRoute',
'middleware::auth:UserOnly',
'controller::auth:Forms.logout_provider_clean_session',
'controller::auth:Forms.logout_provider_present_success',
],
},
}
module.exports = exports = index

View File

@@ -0,0 +1,16 @@
module.exports = exports = {
prefix: '/auth/action', // This is assumed by flitter-auth. Don't change it.
middleware: [],
get: {
'/:key': [
'middleware::auth:KeyAction',
'controller::auth:KeyAction.handle',
],
},
post: {
'/:key': [
'middleware::auth:KeyAction',
'controller::auth:KeyAction.handle',
],
},
}

View File

@@ -0,0 +1,46 @@
/*
* oauth2 Routes
* -------------------------------------------------------------
* Routes pertaining to the flitter-auth OAuth2 server implementation.
*/
const oauth2 = {
// Route prefix for all below routes
prefix: '/auth/service/oauth2/',
middleware: [
// Return 404 errors for these routes if the oauth2 server isn't enabled
['util:Config', {key: 'auth.servers.oauth2.enable'}],
],
get: {
// Show the authorization page
'/authorize': [
'middleware::auth:UserOnly',
'controller::auth:Oauth2.authorize_get',
],
// Built-in data endpoints
// Get the user info using a bearer token
'/data/user': [
['util:Config', {key: 'auth.servers.oauth2.build_in_endpoints.user.enable'}],
'middleware::auth:Oauth2TokenOnly',
'controller::auth:Oauth2.data_user_get',
],
},
post: {
// Handle a successful authorization
'/authorize': [
'middleware::auth:UserOnly',
'controller::auth:Oauth2.authorize_post',
],
// Redeem an authorization code for an OAuth2 bearer token
'/redeem': [
'controller::auth:Oauth2.redeem_token',
],
},
}
module.exports = oauth2