-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e80f36
commit fd476a7
Showing
7 changed files
with
138 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { createAuthenticator } from "@glenstack/cf-workers-access"; | ||
import { FABRuntime } from "@fab/core"; | ||
|
||
const AUTHENTICATION_DOMAIN = "gregbrimble.cloudflareaccess.com"; | ||
const POLICY_AUD = | ||
"95c32a0c3411d058a18ae26e96f95b09f30f59da55f17973018f7f14a7eb6aca"; | ||
|
||
const loginHandler = async (request: Request): Promise<Response> => { | ||
const authenticator = await createAuthenticator(AUTHENTICATION_DOMAIN, { | ||
aud: POLICY_AUD, | ||
}); | ||
|
||
const jwt = await authenticator(request); | ||
|
||
if (jwt) | ||
return new Response(null, { | ||
status: 301, | ||
headers: { Location: "/search" }, | ||
}); | ||
|
||
return new Response(null, { status: 301, headers: { Location: "/" } }); | ||
}; | ||
|
||
export default function login({ Router, ServerContext }: FABRuntime) { | ||
Router.on("/login", ({ request }) => loginHandler(request)); | ||
Router.on("/logout", ({ request }) => | ||
Promise.resolve( | ||
new Response(null, { | ||
status: 301, | ||
headers: { Location: "/cdn-cgi/access/logout" }, | ||
}) | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const webpack = require("webpack"); | ||
|
||
module.exports = { | ||
webpack: (config) => { | ||
config.plugins.push( | ||
new webpack.DefinePlugin({ | ||
window: {}, | ||
}) | ||
); | ||
return config; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters