The reason why I've proposed these updates is case:
1) Would be awesome if we have Imperial OAuth + manual authentication middleware supporting
2) Also, if we gonna use just protectedMiddlewares group we shouldn't split out the oAuth and manual authentication middlewares.
Example:
let protectedMiddlewares: [Middleware] = [
ImperialMiddleware(redirect: "/login/"),
UserModel.redirectMiddleware(path: "/login/"),
UserModel.guardMiddleware(),
ActiveUserMiddleware()
]
let authRequired = app.routes.grouped(protectedMiddlewares)
authRequired.get("myProfile", use: profileController.index)
where UserModel.redirectMiddleware is Authenticatable.redirectMiddleware
And at this point, if a user has been manually authorized, ImperialMiddleware anyway will decline access to this route since the user hasn't accessToken.
If we use my proposed small upade, it might be used like:
let protectedMiddlewares: [Middleware] = [
ImperialMiddleware(redirect: "/login/",
onErrorMiddleware: UserModel.redirectMiddleware(path: "/login/")),
UserModel.guardMiddleware(),
ActiveUserMiddleware()
]
let authRequired = app.routes.grouped(protectedMiddlewares)
authRequired.get("myProfile", use: profileController.index)
where onErrorMiddleware is optional and works only in the case if accessToken doesn't exist.
If I've made something overhead and we have a better solution for the case, please let me know :)
The reason why I've proposed these updates is case: 1) Would be awesome if we have Imperial OAuth + manual authentication middleware supporting 2) Also, if we gonna use just protectedMiddlewares group we shouldn't split out the oAuth and manual authentication middlewares. Example:
where
UserModel.redirectMiddleware
isAuthenticatable.redirectMiddleware
And at this point, if a user has been manually authorized, ImperialMiddleware anyway will decline access to this route since the user hasn't accessToken.If we use my proposed small upade, it might be used like:
where onErrorMiddleware is optional and works only in the case if accessToken doesn't exist.
If I've made something overhead and we have a better solution for the case, please let me know :)