Skip to content

Commit

Permalink
chore: add the wrangler configuration and worker code for auth.ic0.app (
Browse files Browse the repository at this point in the history
dfinity#244)

And fix accessToken which was changed in a parallel PR.
  • Loading branch information
hansl authored Feb 24, 2021
1 parent 3209368 commit 91e9993
Show file tree
Hide file tree
Showing 9 changed files with 905 additions and 6 deletions.
8 changes: 4 additions & 4 deletions apps/identity-provider/src/design-phase-1/ui/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ export default function FlowRoute(props: {
const { path } = useRouteMatch();
const urls = {
identity: {
confirmation: `${path}/identity/confirmation`,
confirmation: `${path}identity/confirmation`,
},
session: {
consent: `${path}/session/consent`,
consent: `${path}session/consent`,
},
response: {
confirmation: `${path}/response/confirmation`,
confirmation: `${path}response/confirmation`,
},
};
const rootIdentity = React.useMemo(() => {
Expand Down Expand Up @@ -113,7 +113,7 @@ export default function FlowRoute(props: {
<MaybeTheme theme={props.theme}>
<AuthenticationScreenLayout>
<Switch>
<Route exact path={`${path}/welcome`}>
<Route exact path={`${path}welcome`}>
<WelcomeScreen
identity={rootSignIdentity}
useIdentity={async identity => {
Expand Down
6 changes: 5 additions & 1 deletion demos/sample-javascript/src/authClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export class AuthenticationClient {
// Remove the `#` at the start.
const hashParams = new URLSearchParams(location.hash.substr(1));

return searchParams.get('access_token') || hashParams.get('access_token') || null;
return searchParams.get('accessToken')
|| searchParams.get('access_token')
|| hashParams.get('accessToken')
|| hashParams.get('access_token')
|| null;
} catch (e) {
// Ignore errors. Return false in that case (maybe the hash params cannot be parsed?).
}
Expand Down
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"apps/*",
"demos/sample-javascript",
"e2e/*",
"packages/*"
"packages/*",
"workers/*"
],
"hoist": [
"@typescript-eslint/eslint-plugin",
Expand Down
2 changes: 2 additions & 0 deletions workers/auth.ic0.app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
worker/
27 changes: 27 additions & 0 deletions workers/auth.ic0.app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getAssetFromKV, serveSinglePageApp } from '@cloudflare/kv-asset-handler';

addEventListener('fetch', event => {
try {
event.respondWith(handleEvent(event))
} catch (e) {
if (DEBUG) {
return event.respondWith(
new Response(e.message || e.toString(), {
status: 500,
}),
)
}
event.respondWith(new Response('Internal Error', { status: 500 }))
}
})

async function handleEvent(event) {
/**
* You can add custom logic to how we fetch your assets
* by configuring the function `mapRequestToAsset`.
* In this case, we serve a single page app from index.html.
*/

const response = await getAssetFromKV(event, { mapRequestToAsset: serveSinglePageApp })
return response
}
Loading

0 comments on commit 91e9993

Please sign in to comment.